您的位置:首页 > 运维架构 > Linux

阿里云linux下修改mysql默认密码(xampp环境)- 原创

2017-07-28 15:12 393 查看
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。



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



注意password里面不要有空格



4.将MySQL的登录设置修改回来
# vi /etc/my.cnf
将刚才在[mysqld]的段中加上的skip-grant-tables删除
保存并且退出vi。

5.重新启动mysqld
# /etc/init.d/mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]

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

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

解决方案:

mysql远程连接 Host * is not allowed to connect to this MySQL server

如果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>use 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>flush privileges;
mysql>select host,user from user where user='root';
mysql>quit

另一种方法

如果你使用的是phpmyadmin我们可以登录phpmyadmin然后在权限管理中进入,这里会看到所有的用户了,你找到root用户点击修改,然后把域修改成%号即可了(注意,你必须是root权限用户登录哦,否则是不可以修改的)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: