1. 程式人生 > 其它 >linux(ubuntu 21.10): apt-get安裝mysql8.0.27

linux(ubuntu 21.10): apt-get安裝mysql8.0.27

一,安裝mysql8

1,更新apt源:
root@lhdpc:~# apt-get update
2,安裝mysql
root@lhdpc:~# apt-get install mysql-server
3,檢查mysql的狀態:
root@lhdpc:~# systemctl status mysql.service
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 
2021-12-20 18:15:45 CST; 38s ago Process: 255962 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS) Main PID: 255970 (mysqld) Status: "Server is operational" Tasks: 38 (limit: 4588) Memory: 352.8M CPU: 2.455s CGroup: /system.slice/mysql.service └─
255970 /usr/sbin/mysqld 12月 20 18:15:43 lhdpc systemd[1]: Starting MySQL Community Server... 12月 20 18:15:45 lhdpc systemd[1]: Started MySQL Community Server.
狀態已是執行中 說明:安裝完成後 mysql的配置檔案位於:
root@lhdpc:~# ll /etc/mysql/mysql.conf.d/mysqld.cnf
-rw-r--r-- 1 root root 2220  3月 13  2021 /etc/mysql/mysql.conf.d/mysqld.cnf
說明:此時可以不用密碼登入mysql, 因為它使用my.cnf中的預設密碼連線 此賬號位於:
root@lhdpc:~# more /etc/mysql/debian.cnf

說明:劉巨集締的架構森林是一個專注架構的部落格,地址:https://www.cnblogs.com/architectforest

對應的原始碼可以訪問這裡獲取:https://github.com/liuhongdi/
或:https://gitee.com/liuhongdi

說明:作者:劉巨集締 郵箱: [email protected]

二,用mysql_secure_installation進行mysql初始化

1,執行mysql_secure_installation
root@lhdpc:~# mysql_secure_installation

會有一系列的問題回答:

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
 
Press y|Y for Yes, any other key for No: n
是否做密碼的強度校驗?選n,生產環境中建議設定一個高強度的密碼
Please set the password for root here.
 
New password:
 
Re-enter new password:
在此處輸入兩次mysql的root賬號密碼
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.
此處輸入Y,用來刪除匿名使用者
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N
 
... skipping.
是否禁止root賬號遠端連線,選n,允許遠端連線
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n
是否刪除test資料庫,選n,不刪,留著
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.
是否重新載入許可權表,選Y,載入 2,測試效果:用剛才設定的root密碼登入
root@lhdpc:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.27-0ubuntu0.21.10.1 (Ubuntu)
 
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
 
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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

三,檢視已安裝mysql的版本:

root@lhdpc:~# whereis mysqld
mysqld: /usr/sbin/mysqld /usr/share/man/man8/mysqld.8.gz
root@lhdpc:~# /usr/sbin/mysqld -V
/usr/sbin/mysqld  Ver 8.0.27-0ubuntu0.21.10.1 for Linux on x86_64 ((Ubuntu))

四,檢視linux版本:

root@lhdpc:~# cat /etc/os-release
PRETTY_NAME="Ubuntu 21.10"
NAME="Ubuntu"
VERSION_ID="21.10"
VERSION="21.10 (Impish Indri)"
VERSION_CODENAME=impish
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=impish