Linux中手動安裝MySQL
阿新 • • 發佈:2022-03-22
步驟一:安裝MySQL
1.執行以下命令更新YUM源:
檢視程式碼
sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
2.安裝MySQL:
檢視程式碼
sudo yum -y install mysql-community-server --enablerepo=mysql80-community --nogpgcheck
3.檢視MySQL版本資訊:
檢視程式碼
mysql -V mysql Ver 8.0.28 for Linux on x86_64 (MySQL Community Server - GPL)
步驟二:配置MySQL
1.啟動MySQL服務
檢視程式碼
systemctl start mysqld
2.設定MySQL服務開機自啟動
檢視程式碼
systemctl enable mysqld
3.檢視/var/log/mysqld.log檔案,獲取並修改root使用者初始化密碼
檢視程式碼
[root@hua30 ~]# grep 'temporary password' /var/log/mysqld.log 2022-03-21T07:55:57.425757Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: w;-14>ww2*E1
4.執行命令:mysql_secure_installation,對MySQL進行安全性配置
檢視程式碼
[root@huan30 ~]# mysql_secure_installation # 1.重置root使用者初始化密碼 Enter password for user root: #輸入已獲取的root使用者初始密碼 The existing password for the user account root has expired. Please set a new password. New password: #輸入新的MySQL密碼 Re-enter new password: #重複輸入新的MySQL密碼 The 'validate_password' component is installed on the server. The subsequent steps will run with the existing configuration of the component. Using existing password for root. Change the password for root ? ((Press y|Y for Yes, any other key for No) :Y #輸入Y選擇更新MySQL密碼。您也可以輸入N不再更新MySQL密碼。 New password: #輸入新的MySQL密碼 Re-enter new password: #重複輸入新的MySQL密碼 Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) :Y #輸入Y確認使用已設定的密碼。 # 2.刪除匿名使用者 By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) :Y #輸入Y刪除MySQL預設的匿名使用者。 Success. # 3.禁止root賬號遠端登入 Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) :Y #輸入Y禁止root遠端登入。 Success. # 4.刪除test庫以及test庫的訪問許可權 By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) :Y #輸入Y刪除test庫以及對test庫的訪問許可權。 - Dropping test database... Success. - Removing privileges on test database... Success. # 5.重新載入授權表 Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) :Y #輸入Y重新載入授權表。 Success. All done!
5.檢視MySQL執行狀態:systemctl status mysqld
檢視程式碼
[root@hua30 ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 一 2022-03-21 15:56:00 CST; 16h ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 23110 (mysqld)
Status: "Server is operational"
Tasks: 40
Memory: 500.7M
CGroup: /system.slice/mysqld.service
└─23310 /usr/sbin/mysqld
3月 21 15:55:54 hua30 systemd[1]: Starting MySQL Server...
3月 21 15:56:00 hua30 systemd[1]: Started MySQL Server.
6.檢視MySQL安裝路徑:find / -name mysql or whereis mysql
檢視程式碼
[root@hua30 ~]# find / -name mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/bin/mysql
/usr/lib64/mysql
/etc/selinux/targeted/active/modules/100/mysql
檢視程式碼
[root@hua30 ~]# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/man/man1/mysql.1.gz
步驟三:登入MySQL
1.登入MySQL資料庫:mysql -u root -p,回車輸入密碼
檢視程式碼
[root@hua30 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 48
Server version: 8.0.28 MySQL Community Server - GPL
Copyright (c) 2000, 2022, 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>