linux上修改mysql登陆密码

1. 修改MySQL的登录设置:  

# vi /etc/my.cnf  

 

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

例如:  

[mysqld]  

port            = 3306

socket          = /application/mysql-5.5.32/tmp/mysql.sock

skip-external-locking

key_buffer_size = 16K

max_allowed_packet = 1M

table_open_cache = 4

sort_buffer_size = 64K

read_buffer_size = 256K

read_rnd_buffer_size = 256K

net_buffer_length = 2K

thread_stack = 128K

skip-grant-tables 

保存并且退出vi

  

3.重新启动mysqld  

# /etc/init.d/mysqld restart  

Stopping MySQL: [ OK ]  

Starting MySQL: [ OK ]  

 

4.登录并修改MySQLroot密码  

# /usr/bin/mysql  

mysql> use mysql ;  

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  

 

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

# vi /etc/my.cnf  

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

保存并且退出vi 

6.重新启动mysqld  

# /etc/init.d/mysqld restart  

Stopping MySQL: [ OK ]  

Starting MySQL: [ OK ]

7. 设置远程登录(可以用Navicat登陆)

登陆mysqlmysql -uroot -p  

回车输入密码

然后运行

mysql> grant all privileges on *.* to '用户名'@'%' identified by '密码' withg rant option; 

mysql> flush privileges ; 

 

posted @ 2018-01-30 16:20  劈天造陆  阅读(658)  评论(0编辑  收藏  举报