1、登錄進(jìn)入mysql,在mysql-5.7.18/bin目錄下執(zhí)行命令:
./mysql -uroot -p -S /usr/local/mysql-5.7.18/data/3307/mysql.sock
其中 -p 是指定密碼,如果沒(méi)有密碼則可以不寫(xiě) -p,-S是指定sock文件,mysql.sock文件是服務(wù)器與本機(jī)客戶端進(jìn)行通信的ip與端口文件;
或者使用用端口、主機(jī)登錄 ./mysql -uroot -p -P3307 -h127.0.0.1 登錄進(jìn)入MySQL
2、修改mysql的密碼,執(zhí)行:
alter user 'root'@'localhost' identified by '123456';(其中123456是我們?cè)O(shè)置的密碼)
3、授權(quán)遠(yuǎn)程訪問(wèn),執(zhí)行命令:(這樣遠(yuǎn)程客戶端才能訪問(wèn))
grant all privileges on *.* to root@'%' identified by '123456';
其中*.* 的第一個(gè)*表示所有數(shù)據(jù)庫(kù)名,第二個(gè)*表示所有的數(shù)據(jù)庫(kù)表;
root@'%' 中的root表示用戶名,%表示ip地址,%也可以指定具體的ip地址,比如root@localhost,root@192.168.10.129
4、執(zhí)行以下如下命令刷新權(quán)限:
flush privileges;
以上步驟一次性執(zhí)行:
alter user 'root'@'localhost' identified by '123456';
grant all privileges on *.* to root@'%' identified by '123456';
flush privileges;