如何設定mysql root密碼,mysqlroot密碼

來源:互聯網
上載者:User

如何設定mysql root密碼,mysqlroot密碼
如何設定mysql root密碼:


1、首次安裝 root初始密碼為空白,注意就是沒有密碼,直接敲斷行符號即可進入
D:\wamp\bin\mysql\mysql5.6.17\bin>mysql -uroot -p
Enter password:  [直接斷行符號]
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.17 MySQL Community Server (GPL)


Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql>


2、修改root密碼的幾種方法:
1) 用SET PASSWORD命令
  首先登入MySQL。
  格式:mysql> set password for 使用者名稱@localhost = password('新密碼');

  例如:


mysql> set password for root@localhost = password('root');
Query OK, 0 rows affected (0.00 sec)


mysql> quit
Bye


D:\wamp\bin\mysql\mysql5.6.17\bin> mysql -uroot -proot
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.6.17 MySQL Community Server (GPL)


Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> 


2)用mysqladmin
  格式:mysqladmin -u使用者名稱 -p舊密碼 password 新密碼
  例如:
D:\wamp\bin\mysql\mysql5.6.17\bin> mysqladmin -uroot -proot password root123
Warning: Using a password on the command line interface can be insecure.


D:\wamp\bin\mysql\mysql5.6.17\bin> mysql -uroot -proot123
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.6.17 MySQL Community Server (GPL)


Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql>


3)用UPDATE直接編輯user表
  首先登入MySQL。
   mysql> use mysql;
  mysql> update user set password=password('root') where user='root' and host='localhost';
  mysql> flush privileges;

--注意一定要flush privileges;
mysql 新設定使用者或更改密碼後需用flush privileges重新整理MySQL的系統許可權相關表,否則會出現拒絕訪問,還有一種方法,就是重新啟動mysql伺服器,來使新設定生效。


4)在忘記root密碼的時候,可以這樣。
  以windows為例:
  1. 關閉正在啟動並執行MySQL服務。
  2. 開啟DOS視窗,轉到mysql\bin目錄。
  3. 輸入mysqld --skip-grant-tables 斷行符號。--skip-grant-tables 的意思是啟動MySQL服務的時候跳過許可權表認證。
  4. 再開一個DOS視窗(因為剛才那個DOS視窗已經不能動了),轉到mysql\bin目錄。
  5. 輸入mysql斷行符號,如果成功,將出現MySQL提示符 >。
  6. 串連許可權資料庫: use mysql; 。
  6. 改密碼:update user set password=password('root123') where user='root';(別忘了最後加分號) 。
  7. 重新整理許可權(必須步驟): flush privileges; 
  8. 退出quit當前cmd,並且關閉2中的DOS視窗

  9. 使用使用者名稱root,新密碼root123在4中DOS視窗登入。


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

Dylan    Presents.


相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.