由于又一次在折騰 MySQL 配置問題上浪費(fèi)了不少時(shí)間,由此整理一下,以備不時(shí)之需。
系統(tǒng):
- Windows10
- MySQL5.7.17
** 說明: ** 以下命令均需要在管理員賬號(hào)在 bin 執(zhí)行,【】里面的內(nèi)容為可選項(xiàng)
- 修改 my.ini : 設(shè)置 basedir 和 datadir 目錄,datadir 可不設(shè),默認(rèn)在 basedir 目錄下自動(dòng)生成。
- 初始化:
mysqld --initialize[-insecure -user=root], 加上 insecure 參數(shù)不會(huì)設(shè)置隨機(jī)密碼 - 安裝:
mysqld --install [ service_name] [ --defaults-file="C:\Program Files\mysql\my.ini"]
如果成功會(huì)回顯:Service successfully installed. - 啟動(dòng)服務(wù):
net start mysql,類似停止為:stop - 卸載服務(wù):
sc delete MySQL, 以及mysqld -remove - 首次登陸問題:
- 以安全模式打開:
mysqld --skip-grant-tables后新建窗口無密碼登陸:mysql -uroot -p然后:use mysql;update user set password=password("123456") where user="root";修改密碼,flush privileges刷新后 kill 掉 mysqld 進(jìn)程即可正常登陸。如果提示通過alter user修改密碼:alter user 'root'@'localhost' identified by 'password';
- 看到其他的方法可能適用于其他版本:首次無密碼登陸后通過
mysqladmin -uroot password修改密碼,1054錯(cuò)誤:在 my.ini 文件 [mysqld]條目下添加:skip-grant-tables和上面參數(shù)一樣的,’use mysql' 后update user set authentication_string=password("...") where user="root"設(shè)置密碼。 - 授權(quán):
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
密碼
- 修改密碼:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'npassword'set password for 'root'@'localhost' password('admin')
另外貼一篇MySQL5.6 my.cnf配置優(yōu)化,
以及 MySQL官方的文檔,以備查詢。