1. 程式人生 > >linux 部署之路 修行不夠全靠悟

linux 部署之路 修行不夠全靠悟

考慮到很多孩子不會Linux或Mysql,所以我這裡提示一下,

這篇教程裡 "有多行程式碼" 的是給你展示結果的,不用你敲

只有一行的才是要你自己敲進去的.

 

1.首先更新一下倉庫

sudo apt-get update
2.安裝mysql

sudo apt-get install -y mysql-server mysql-client
3.檢查mysql是否已執行

sudo netstat -tap | grep mysql
有顯示就是已執行

4.查詢預設的使用者名稱和密碼

(提示:sudo命令會讓你輸入你的使用者密碼,就是你的開機密碼,並且你輸入的時候看不到自己輸入的內容,不要以為電腦卡住了,輸完回車就行)

sudo cat 
/etc/mysql/debian.cnf 顯示出來的內容格式如下(我的密碼,跟你不一樣) [email protected]-PC:~$ sudo cat /etc/mysql/debian.cnf # Automatically generated for Debian scripts. DO NOT TOUCH! [client] host = localhost user = debian-sys-maint password = F64nKZ233QkzL8v9 socket = /var/run/mysqld/mysqld.sock [mysql_upgrade] host
= localhost user = debian-sys-maint password = F64nKZ233QkzL8v9 socket = /var/run/mysqld/mysqld.sock 其中user代表的使用者名稱,password代表的預設生成的密碼 5.利用預設賬號密碼登入(-p後面是我的密碼,你們要把自己的密碼放在那裡,並且-p跟密碼之間無空格) mysql -u debian-sys-maint -pF64nKZ233QkzL8v9 成功進入mysql,有如下顯示: [email protected]-PC:~$ mysql -u debian-sys-maint -pF64nKZ233QkzL8v9 mysql: [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 3 Server version: 5.7.21-1 (Debian) Copyright (c) 2000, 2018, 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> 6.現在更改密碼的設定.(原封不動複製過去,漏一個字你就完了),這是最重要的部分,很多教程都沒有這個,所以才不管用 update mysql.user set plugin="mysql_native_password" where user="root"; 成功後結果如下: mysql> update mysql.user set plugin="mysql_native_password" where user="root"; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> 7.設定root的密碼 update mysql.user set authentication_string=password('這裡是你的密碼') where user='root'and Host = 'localhost'; 密碼自己設定 8.退出資料庫 exit 9.重新啟動資料庫 sudo service mysql restart 10.用自己設定好的密碼登入 mysql -u root -p 輸入密碼,成功登入,如下. [email protected]-PC:~$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.21-1 (Debian) Copyright (c) 2000, 2018, 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> nice! ---------------------