您好,登錄后才能下訂單哦!
為了演示,找個(gè)測(cè)試環(huán)境來操作,千萬不要線上這么搞
pkill mysqld 關(guān)閉掉mysql
跳過MySQL的權(quán)限表啟動(dòng)MySQL服務(wù):
--skip-grant-tables啟動(dòng)mysql
/usr/local/mysql8013/bin/mysqld_safe --defaults-file=/data/mysql8/my8.cnf --skip-grant-tables &
將密碼置空:
root@localhost [(none)]>update mysql.user set authentication_string='' where user="root" and host="localhost";
Query OK, 1 row affected (0.06 sec)
Rows matched: 1 Changed: 1 Warnings: 0
root@localhost [(none)]>
pkill mysqld 關(guān)閉掉mysql
再次啟動(dòng)mysql服務(wù)
[root@localhost ~]# /usr/local/mysql8013/bin/mysqld --defaults-file=/data/mysql8/my8.cnf &
無密碼登錄MySQL服務(wù)并設(shè)置新的密碼:
root@localhost [(none)]>select version();
+-----------+
| version() |
+-----------+
| 8.0.13 |
+-----------+
root@localhost [(none)]>alter user user() identified by 'jist558@wei';
[root@localhost ~]# mysql -uroot -p'jist558@wei' -e "select version();"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-----------+
| version() |
+-----------+
| 8.0.13 |
+-----------+
密碼寫入.my.cnf文件就可以mysql直接登錄mysql窗口:
[root@localhost ~]# cat .my.cnf
[mysql]
prompt="\u@\h:\p \R:\m:\s[\d]>"
no-auto-rehash
user=root
password=jist558@wei
[root@localhost ~]# mysql -e "select version();"
+-----------+
| version() |
+-----------+
| 8.0.13 |
+-----------+
演示完畢
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。