Ubuntu安装MySQL Access denied for user 'root'@'192.168.1.148' (using password: YES)

Ubuntu version 16.0.4
Ubuntu installation is relatively simple, just need three commands
1, sudo apt-get install mysql-server
prompt to continue to execute Y

Wait for the prompt to set a password, this password is the password to log in to the database in the future

Repeat the password set in the previous step

2、sudo apt-get install mysql-client

3. sudo apt-get install libmysqlclient-dev
Enter Y to continue execution, waiting for the installation to succeed

4. How to open Mysql remote access under Ubuntu

4.1 Open port 3306

First confirm whether port 3306 is open to the public. By default, mysql is not open to external access. The viewing method is as follows:

# netstat -an | grep 3306
tcp    0   0 127.0.0.1:3306      0.0.0.0:*         LISTEN

As can be seen from the above, mysql port 3306 is just listening for local connections 127.0.0.1. We make changes to make it open to other addresses. Open /etc/mysql/my.cnffile

# vim /etc/mysql/my.cnf

Find bind-address = 127.0.0.1this line, probably on line 47, we will comment it out.

4.2 Remote access by authorized users

In order to allow users who access the mysql client to have access rights, we can authorize users by the following methods: First enter mysql

# mysql -uroot -p

  #Enter your_password

Authorization:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your_password' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;

Otherwise, the following problems will occur

Access denied for user 'root'@'192.168.1.148' (using password: YES)

4.3 Restart the mysql service to make the configuration take effect

The restart method is simple:

# sudo service mysql restart

 

78 original articles published · 32 praised · 120,000 views

Guess you like

Origin blog.csdn.net/caofengtao1314/article/details/103309222