Mysql初始化root密码和允许远程访问
mysql默认root用户没有密码,输入mysql –u root 进入mysql
方法1: 用SET PASSWORD命令mysql -u rootmysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
方法2: mysql>update user set password=PASSWORD(‘123456’) where user='root';
允许mysql远程访问,可以使用以下三种方式:
a、改表。
mysql -u root –p
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
b、授权。
例如,你想root使用123456从任何主机连接到mysql服务器。
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
如果你想允许用户jack从ip为10.10.50.127的主机连接到mysql服务器,并使用654321作为密码
mysql>GRANT ALL PRIVILEGES ON *.* TO 'jack'@’10.10.50.127’ IDENTIFIED BY '654321' WITH GRANT OPTION;
mysql>FLUSH PRIVILEGES;
c、在安装mysql的机器上运行:
//进入MySQL服务器
d:\mysql\bin\>mysql -h localhost -u root
//赋予任何主机访问数据的权限
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
//使修改生效
mysql>FLUSH PRIVILEGES;
//退出MySQL服务器
mysql>EXIT;