Mysql初始化root密码和允许远程访问

mysql默认root用户没有密码,输入mysql –u root 进入mysql

1、初始化root密码

进入mysql数据库

mysql>update user set password=PASSWORD('123456') where User='root';

2、允许mysql远程访问,有以下几中方式

如果不允许远程访问,会报如下的错误:

ERROR 1130 (HY000): Host ‘1.2.3.4’ is not allowed to connect to this MySQL server

(1)、Change mysql config

vim /etc/mysql/my.cnf

Comment out following lines.

#bind-address           = 127.0.0.1
#skip-networking

If you do not find skip-networking line, add it and comment out it.

Restart mysql server.

/etc/init.d/mysql restart

(2)、Change GRANT privilege

Run a command like below to access from all machines. (Replace USERNAME and PASSWORD by your credentials.)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'%' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;

Run a command like below to give access from specific IP. (Replace USERNAME and PASSWORD by your credentials.)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'1.2.3.4' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;

Finally, you may also need to run:

mysql> FLUSH PRIVILEGES;
原文地址:https://www.cnblogs.com/ahang/p/6805921.html