PHP MariaDB access denied for root#localhost through browser without sudo - php

I am trying to create a new database as root, which has no password set. I log in from the command line using sudo to access root without a problem. Using a PHP script to create a database as root, I don't provide a password and I get Access denied for user 'root'#'localhost'. I'm not supposed to include my sudo password in the script, right?
I can get this script to run if I run it with 'testuser', a user I created as root from the MariaDB shell, but this user does not have any privileges, and I don't want to grant it privileges on all databases, so I need to create one first. I have tried setting a password for the root user in the database shell and including this in the script, but this has the same result. How do I get access through a PHP script?

Related

SQL Cannot Log in

[] I keep on getting this message what could be the problem 1
This means that your username/password is not correct.
If you forgot your root password, you can recover it using the instruction in this link (I'm assuming from your screenshot that you are using Windows)
https://dev.mysql.com/doc/mysql-windows-excerpt/5.7/en/resetting-permissions-windows.html
On Windows, use the following procedure to reset the password for the MySQL 'root'#'localhost' account. To change the password for a root account with a different host name part, modify the instructions to use that host name.
Log on to your system as Administrator.
Stop the MySQL server if it is running. For a server that is running as a Windows service, go to the Services manager: From the Start menu, select Control Panel, then Administrative Tools, then Services. Find the MySQL service in the list and stop it.
If your server is not running as a service, you may need to use the Task Manager to force it to stop.
Create a text file containing the password-assignment statement on a single line. Replace the password with the password that you want to use.
MySQL 5.7.6 and later:
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';
MySQL 5.7.5 and earlier:
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('MyNewPass');
Save the file. This example assumes that you name the file C:\mysql-init.txt.
Open a console window to get to the command prompt: From the Start menu, select Run, then enter cmd as the command to be run.
Start the MySQL server with the special --init-file option (notice that the backslash in the option value is doubled):
C:\> cd "C:\Program Files\MySQL\MySQL Server 5.7\bin"
C:\> mysqld --init-file=C:\\mysql-init.txt
If you installed MySQL to a different location, adjust the cd command accordingly.
The server executes the contents of the file named by the --init-file option at startup, changing the 'root'#'localhost' account password.
To have server output to appear in the console window rather than in a log file, add the --console option to the mysqld command.
If you installed MySQL using the MySQL Installation Wizard, you may need to specify a --defaults-file option. For example:
C:\> mysqld
--defaults-file="C:\\ProgramData\\MySQL\\MySQL Server 5.7\\my.ini"
--init-file=C:\\mysql-init.txt
The appropriate --defaults-file setting can be found using the Services Manager: From the Start menu, select Control Panel, then Administrative Tools, then Services. Find the MySQL service in the list, right-click it, and choose the Properties option. The Path to executable field contains the --defaults-file setting.
After the server has started successfully, delete C:\mysql-init.txt.
You should now be able to connect to the MySQL server as root using the new password. Stop the MySQL server and restart it normally. If you run the server as a service, start it from the Windows Services window. If you start the server manually, use whatever command you normally use.
If the ALTER USER statement fails to reset the password, try repeating the procedure using the following statements to modify the user table directly:
UPDATE mysql.user
SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N'
WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;
Follow the instruction and you will be fine.

Apache and Mysql using Ubuntu mate

I'm new to Ubuntu. I tried to run a .php file and connect it to a database. Everything is on-set. I already imported the database in phpMyAdmin but every time I access my database,it returns an error
This page isn’t working localhost is currently unable to handle this
request. HTTP ERROR 500
Turns out, it seems like my database isn't running at all. In Windows I just open the XAMPP and click Apache and MySQL buttons. While in Ubuntu,
I have no idea on how to start or run MySQL and Apache. I already tried running commands on the terminal but it won't help. Someone has already installed it on this computer, I just don't how to run it and what web-server platform is this running.
How do I do it and how would I know that my database is running and accessible?
Try to connect your database and access database via command line.
mysql -u [username] -p
you can replace [username] with your real username of mysql like root
it will prompt for password so you are type yours like root
prompt will say
mysql>
now you need to list all databases to see is database exists or not
show databases;
it will list down all databases. you may verify is your exists or not
then you can select database by
use databasename;
and then run
show tables;
it will show all tables.
so you can verify that mysql working, database exists and tables are there or not.
Use this command it will start the database is you have it
systemctl mysql start
This should do the trick you need to have mysql database or maria db installed
Check by running this command in terminal after the first one
mysql
And you can also add argument like host and login
mysql -h (your host default is localhost) -u (user default is root) -p (password default is none)
Check your files access level
sudo chmod -R 777 "location of your file"

Cannot connect to MySQL server on Openshift

Recently, I've started using openshift & also deployed an application using PHP & MySQL. Yesterday, out of curiosity, I've removed the password for phpMyAdmin and guess what, now I'm unable to log in to both phpMyAdmin & mysql database.
I've tried both the passwords (the default one & the empty password) and uninstalled & re-installed the PHPmyAdmin catridge & also, force restarted the app several times but nothing worked. Now, I've no idea what happened. Any help is appreciated.
Hopefully this will help.
I assume what you did was go into phpmyadmin and click on 'users' then 'edit privileges' for one of the users, select 'no password' and hit save right? If so, then I think the following steps should help.
1.) ssh into your gear (you can use the rhc ssh command)
2.) run the mysql command
3.) You should get an error like this ERROR 1045 (28000): Access denied for user 'adminslULJTS'#'127.10.126.130' (using password: YES)
4.) Now, type in the command mysql -u $OPENSHIFT_MYSQL_DB_USERNAME -h $OPENSHIFT_MYSQL_DB_HOST -P $OPENSHIFT_MYSQL_DB_PORT -p
5.) When it asks for a password, just hit enter
6.) You should now be logged into the mysql shell
Now you need to reset your password to what openshift thinks it is.
1.) create another ssh session into your gear in another terminal, leaving the old one open
2.) run the command env | grep MYSQL
3.) this will give you the following information that you will need to reset your password:
OPENSHIFT_MYSQL_DB_HOST=127.10.126.130
OPENSHIFT_MYSQL_DB_PASSWORD=Il8-rVLIKSrx
OPENSHIFT_MYSQL_DB_USERNAME=adminslULJTS
Given the above information, go back to your ssh session that had the mysql connection open, and enter the following command:
set password for 'adminslULJTS'#'127.10.126.130' = PASSWORD('Il8-rVLIKSrx');
But you will need to replace the username, host, and password with the ones you got from the above step.
You should now be able to log into phpmyadmin with your old username & password that you can either view using the env | grep MSYQL command, or view in the web console for your application at openshift.com
It also might be worth reviewing this KB article: https://www.openshift.com/kb/kb-e1085-possible-complications-when-changing-your-database-credentials

SQLSTATE[28000][1045] Access denied for user 'root'#'localhost'(using password:NO)

When I try to connect to my backoffice in my website I get this error :
SQLSTATE[28000][1045]Access denied for user 'root'#'localhost'(using password:NO))
Can someone help me fix this?
You must use a password. Try to set one with "mysqladmin -u root password NEWPASSWORD"
You need to supply a password when logging into your database. When you connect to sql from php, make sure you're supplying this password.
If you set a root password previously, but have forgotten it, you can set a new password. I am working on a Windows machine, and was able to reset the password on the root of MySql using the directions http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html. I created a text file (mysql-init.txt) as follows:
UPDATE mysql.user SET Password=PASSWORD('[choose your password')
WHERE User='root';
FLUSH PRIVILEGES;
At the command line, I entered the following (either make sure you are in the mysql\bin directory or that your path environment variable includes a path to that directory), which will start the server:
mysqld --init-file=C:\\mysql-init.txt --console
This printed out a bunch of status statements. To stop the server, I typed this in another command line:
mysqladmin –u root –p[choose your password] shutdown
Of course, replace the [choose your password] with the same password you used in the mysql-init.txt file. In the first command line, you should get more status statements that indicate that the server is shutting down.
Now that you have a password for your root user, you can go back to the connection statement you are using to connect to the database and add the password and user.

Can't login to phpmyadmin

I am new at linux but I beed phpmyadmin on my centos server. I did this:
cd /var/www/html/ (document root of apache)
wget http://sourceforge.net/projects/phpmyadmin/path/to/latest/version
tar xvfz phpMyAdmin-3.3.9-all-languages.tar.gz
mv phpMyAdmin-3.3.9-all-languages phpmyadmin
rm phpMyAdmin-3.3.9-all-languages.tar.gz
cd phpmyadmin/
cp config.sample.inc.php config.inc.php
When I go to www.$ip/phpmyadmin and I am presented with a login screen asking for username and password. How can I get these credentials to log in? I'd like to log in as root I guess. But I don't know how to setup a root account and create a password for root using the cli and mysql. Please help? Thanks.
To set the mysql root password try the following:
$ mysqladmin -u root password NEWPASSWORD
If you've never set the mysql password before, you won't have a password yet.
Also it's important to remember that the mysql root user and the system root user are different. (And they should have different passwords)
More information is available from here: http://www.cyberciti.biz/faq/mysql-change-root-password/
I had a problem with making login by phpMyAdmin with new user which I was created in phpMyAdmin as root. I added the new user with all ALL PRIVILEGES and there was no effect.
Finally, I created the new user by MySQL Command Line Shell and everything became all right.
I did it by following commands:
GRANT ALL ON *.* TO 'new_username'#'localhost' IDENTIFIED BY 'password_for_new_user';
FLUSH PRIVILEGES;
I found the description HERE
You are logging in to MySQL through phpMyAdmin, so the username and password you use would be the MySQL username and password.
From the default setup, it should be a username and password from the MySQL database itself. So if you have a user account for the MySQL database, use that.

Categories