I just installed Ubuntu 16.04 and installed web server on it. Everything works well, but I cannot access database. Even if I create new user and grant all privileges, I can\
These steps worked for me on several Systems using Ubuntu 16.04, Apache 2.4, MariaDB, PDO
log into MYSQL as root
mysql -u root
Grant privileges. To a new user execute:
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost';
FLUSH PRIVILEGES;
UPDATE for Google Cloud Instances
MySQL on Google Cloud seem to require an alternate command (mind the backticks).
GRANT ALL PRIVILEGES ON `%`.* TO 'newuser'@'localhost';
bind to all addresses:
The easiest way is to comment out the line in your /etc/mysql/mariadb.conf.d/50-server.cnf or /etc/mysql/mysql.conf.d/mysqld.cnf file, depending on what system you are running:
#bind-address = 127.0.0.1
exit mysql and restart mysql
exit
service mysql restart
By default it binds only to localhost, but if you comment the line it binds to all interfaces it finds. Commenting out the line is equivalent to bind-address=*.
To check the binding of mysql service execute as root:
netstat -tupan | grep mysql
If you are receiving that error even after creating a new user and assigning them the database previledges, then the one last thing to look at is to check if the users have been assigned the preiveledges in the database.
To do this log into to your mysql(This is presumably its the application that has restricted access to the database but you as a root can be ablr to access your database table via mysql -u user -p)
commands to apply
mysql -u root -p
password: (provide your database credentials)
on successful login
type
use mysql;
from this point check each users priveledges if it is enabled from the db table as follows
select User,Grant_priv,Host from db;
if the values of the Grant_priv col for the created user is N update that value to Y with the following command
UPDATE db SET Grant_priv = "Y" WHERE User= "your user";
with that now try accessing the app and making a transaction with the database.
To create user for phpMyAdmin :
sudo mysql -p -u root
Now you can add a new MySQL user with the username of your choice.
CREATE USER 'USERNAME'@'%' IDENTIFIED BY 'PASSWORD';
And finally grant superuser privileges to the user you just created.
GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'%' WITH GRANT OPTION;
For any question, please leave a comment
Turns out you can't use the root
user in 5.7 anymore without becoming a sudoer. That means you can't just run mysql -u root
anymore and have to do sudo mysql -u root
instead.
That also means that it will no longer work if you're using the root
user in a GUI (or supposedly any non-command line application). To make it work you'll have to create a new user with the required privileges and use that instead.
See this answer for more details.
Just Create New User for MySQL do not use root. there is a problem its security issue
sudo mysql -p -u root
Login into MySQL or MariaDB with root privileges
CREATE USER 'troy121'@'%' IDENTIFIED BY 'mypassword123';
login and create a new user
GRANT ALL PRIVILEGES ON *.* TO 'magento121121'@'%' WITH GRANT OPTION;
and grant privileges to access "." and "@" "%" any location not just only 'localhost'
exit;
if you want to see your privilege table SHOW GRANTS;
& Enjoy.
Maybe a bit late, but I found this answer looking over the internet. It could help others with the same problem.
$sudo mysql -u root
[mysql] use mysql;
[mysql] update user set plugin='' where User='root';
[mysql] flush privileges;
[mysql] \q
Now you should be able to log in as root in phpmyadmin.
(Found here.)