mysql 重置root密码 远程访问_重置mysql的root密码以及设置mysql远程登陆权限
root
密碼忘記,重置mysql的root密碼
:t
一、修改mysql的配置文件my.cnf
1.
在[mysqld]的段中加上一句:skip-grant-tables
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-name-resolve
skip-grant-tables
保存并且退出vi。
(
或執行?mysqld_safe?--skip-grant-tables?&
)
2.重新啟動mysqld
#?/etc/init.d/mysqld?restart
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 authentication_string = password('root'), password_expired = 'N', password_last_changed = now() 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
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服務
/etc/init.d/mysqld?stop
sudo?mysqld_safe?--skip-grant-table&
mysql
use?mysql;
update?user?set?password?=?password('yourpasswd')?where?user?=?'root';
flush?privileges;
重啟下mysql服務即可重新用新密碼登錄
/etc/init.d/mysqld?restart
允許遠程連接mysql
通過navicat連接MySQL的時候發生的這個錯誤
ERROR?1130:?Host?***.***.***.***?is?not?allowed?to?connect?to?this?MySQL?server
說明所連接的用戶帳號沒有遠程連接的權限,只能在本機(localhost)登錄。
需更改?MySQL?數據庫里的?user表里的?host項
把localhost改稱%
一、
登陸到MySQL?,首先?use?MySQL;
按照別人提供的方式update的時候,出現錯誤。
MySQL>?update?user?set?host='%'?where?user?=?'root';
ERROR?1062?(23000):?Duplicate?entry?'%-root'?for?key?'PRIMARY'
然后查看了下數據庫的host信息如下:
MySQL>?select?host?from?user?where?user?=?'root';
+-----------------------+
|?host?|
+-----------------------+
|?%?|
|?127.0.0.1?|
|?localhost.localdomain?|
+-----------------------+
3?rows?in?set?(0.00?sec)
host已經有了%這個值,所以直接運行命令:
MySQL>flush?privileges;
二、
mysql>
grant?all?privileges?on?*.*?to?'root'@'%'?with?grant?option;
Query?OK,?0?rows?affected?(0.02?sec)
mysql>
flush?privileges;
Query?OK,?0?rows?affected?(0.00?sec)
mysql>
selectuser.host?from?user;
+-----------+--------------+
|?user|?host|
+-----------+--------------+
|?root|
%
|
|?root|?127.0.0.1|
|?repl_user?|?192.168.1.52?|
+-----------+--------------+
3?rows?in?set?(0.00?sec)
允許指定
IP
訪問
mysql
mysql>
grant?all?privileges?on?*.*?to
'root'@116.224.126.250
identified?by?'123456';
QueryOK,?0?rows?affected?(0.00?sec)
總結
以上是生活随笔為你收集整理的mysql 重置root密码 远程访问_重置mysql的root密码以及设置mysql远程登陆权限的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql服务器的线程数查看方法_MyS
- 下一篇: linux mysql odbc驱动安装