天天看点

阿里云linux下修改mysql默认密码(xampp环境)- 原创mysql远程连接 Host * is not allowed to connect to this MySQL server

1.修改MySQL的登录设置: 

# vi /etc/my.cnf 

在[mysqld]的段中加上一句:skip-grant-tables 

例如: 

[mysqld] 

datadir=/var/lib/mysql 

socket=/var/lib/mysql/mysql.sock 

skip-grant-tables 

保存并且退出vi。 

阿里云linux下修改mysql默认密码(xampp环境)- 原创mysql远程连接 Host * is not allowed to connect to this MySQL server

2.重新启动mysqld 

停止 MySQL 数据库

/opt/lampp/lampp stopmysql

只启动 MySQL 数据库

/opt/lampp/lampp startmysql

Stopping MySQL: [ OK ] 

Starting MySQL: [ OK ] 

3.登录并修改MySQL的root密码 

# /usr/bin/mysql 

Welcome to the MySQL monitor. Commands end with ; or \g. 

Your MySQL connection id is 3 to server version: 3.23.56 

Type 'help;' or '\h' for help. Type '\c' to clear the buffer. 

mysql> USE mysql ; 

Reading table information for completion of table and column names 

You can turn off this feature to get a quicker startup with -A 

Database changed 

mysql> UPDATE user SET Password = password ('new-password') WHERE User = 'root' ; 

Query OK, 0 rows affected (0.00 sec) 

Rows matched: 2 Changed: 0 Warnings: 0 

mysql> flush privileges ; 

Query OK, 0 rows affected (0.01 sec) 

mysql> quit 

Bye 

阿里云linux下修改mysql默认密码(xampp环境)- 原创mysql远程连接 Host * is not allowed to connect to this MySQL server

 注意password里面不要有空格

阿里云linux下修改mysql默认密码(xampp环境)- 原创mysql远程连接 Host * is not allowed to connect to this MySQL server

4.将MySQL的登录设置修改回来 

将刚才在[mysqld]的段中加上的skip-grant-tables删除 

5.重新启动mysqld 

# /etc/init.d/mysqld restart 

Starting MySQL: [ OK ]

----------------------------------------------------------------------------------------------------------------------------

同时需要支持下mysql远程连接,否则会出现bug:   Host 'XXX' is not allowed to connect to this MySQL server 解决方案/如何开启MySQL的远程帐号

解决方案:

如果mysql不支持远程连接,会出现提示:错误代码是1130,ERROR 1130: Host * is not allowed to connect to this MySQL server ,

解决此问题有以下2个方法:

localhost改成%

进入mysql的BIN目录

 代码如下

复制代码

mysql -u root -p

mysql>use mysql;

mysql>update user set host =’%' where user =’root’;

mysql>flush privileges;

具体分析

1、在本机登入mysql后,更改“mysql”数据库里的“user”表里的“host”项,从”localhost”改为'%'。

mysql>

mysql>select 'host' from user where user='root';     

   #查看mysql库中的user表的host值(即可进行连接访问的主机/IP名称)

mysql>update user set host = '%' where user ='root';

#修改host值(以通配符%的内容增加主机/IP地址,当然也可以直接增加某个特定IP地址,如果执行update语句时出现ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY' 错误,需要select host from user where user = 'root';

查看一下host是否已经有了%这个值,如果有了直接执行下面的flush privileges;即可)

mysql>select host,user from user where user='root';

mysql>quit

另一种方法

如果你使用的是phpmyadmin我们可以登录phpmyadmin然后在权限管理中进入,这里会看到所有的用户了,你找到root用户点击修改,然后把域修改成%号即可了(注意,你必须是root权限用户登录哦,否则是不可以修改的)

如何联系我:【万里虎】www.bravetiger.cn

【QQ】3396726884 (咨询问题100元起,帮助解决问题500元起)

【博客】http://www.cnblogs.com/kenshinobiy/