您的位置:首页 > 数据库 > MySQL

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

2017-05-04 11:04 411 查看
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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: