測試環境為 CentOS7 (虛擬機)
從 CentOS 7 之後預設的資料庫系統為 MariaDB ,這邊來安裝 MySQL 5.7.43-1
我們無法直接從標準的 yum 去找到 mysql server 資料套件.
[root@localhost ~]# yum install mysql-community-server Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: centos.ccns.ncku.edu.tw * epel: ftp.iij.ad.jp * extras: centos.ccns.ncku.edu.tw * updates: centos.ccns.ncku.edu.tw No package mysql-community-server available. Error: Nothing to do
需先去下載 mysql80-community 的 Repository (預設路徑位於 /etc/yum.repos.d/) , 可以發現多了2個 mysql-community.repo 與 mysql-community-source.repo
[root@localhost ~]# yum -y localinstall https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Loaded plugins: fastestmirror, langpacks mysql80-community-release-el7-3.noarch.rpm | 25 kB 00:00:00 Examining /var/tmp/yum-root-hmoP2j/mysql80-community-release-el7-3.noarch.rpm: mysql80-community-release-el7-3.noarch Marking /var/tmp/yum-root-hmoP2j/mysql80-community-release-el7-3.noarch.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package mysql80-community-release.noarch 0:el7-3 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================== Package Arch Version Repository Size ======================================================================================================================== Installing: mysql80-community-release noarch el7-3 /mysql80-community-release-el7-3.noarch 31 k Transaction Summary ======================================================================================================================== Install 1 Package Total size: 31 k Installed size: 31 k Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : mysql80-community-release-el7-3.noarch 1/1 Verifying : mysql80-community-release-el7-3.noarch 1/1 Installed: mysql80-community-release.noarch 0:el7-3 Complete!
透過 yum-config-manager 去選擇安裝 Mysql 版本為 5.7
[root@localhost ~]# yum-config-manager --disable mysql80-community [root@localhost ~]# yum-config-manager --enable mysql57-community [root@localhost ~]# yum repolist enabled | grep "mysql.*-community.*" mysql-connectors-community/x86_64 MySQL Connectors Community 227 mysql-tools-community/x86_64 MySQL Tools Community 100 mysql57-community/x86_64 MySQL 5.7 Community Server 678
系統預設沒有 Mysql RPM GPG Key (避免使用者安裝到不安全的 rpm 檔案),這邊一併匯入.
[root@localhost ~]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
開始安裝 MySQL 5.7
[root@localhost ~]# yum install mysql-community-server
啟動服務.
[root@localhost ~]# systemctl start mysqld [root@localhost ~]# systemctl enable mysqld [root@localhost ~]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2023-07-27 20:13:59 PDT; 11s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Main PID: 2862 (mysqld) CGroup: /system.slice/mysqld.service └─2862 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
檢視安裝的版本.
[root@localhost ~]# mysqld -V mysqld Ver 5.7.43 for Linux on x86_64 (MySQL Community Server (GPL))
預設的 Mysql 的 root ( 非 Linux 系統 root) 的密碼儲存在檔案 /var/log/mysqld.log.
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
下面指令主要是要重設 Mysql 的 root ( 非 Linux 系統 root) 的密碼,這邊密碼設定需符合 複雜性要求 ( 長度至少八個字元 其中需包含 大寫字母 , 小寫字母 , 數字與 特殊符號各一個)
[root@localhost ~]# mysql_secure_installation Securing the MySQL server deployment. Enter password for user root: VALIDATE PASSWORD PLUGIN 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 plugin? Press y|Y for Yes, any other key for No: Using existing password for root. Change the password for root ? ((Press y|Y for Yes, any other key for No) : ... skipping.
是否移除 anonymous 匿名者帳號.
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) : ... skipping.
是否允許 root 可以從非本機 (localhost) 登入.
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) : ... skipping.
是否移除 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) : ... skipping.
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) : ... skipping. All done!
設定完成,測試一下資料庫是否正常.
[root@localhost ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 14 Server version: 5.7.43 MySQL Community Server (GPL) Copyright (c) 2000, 2023, 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> exit; Bye
沒有解決問題,試試搜尋本站其他內容