table of Contents
Reference: MySQL official-A Quick Guide to Using the MySQL Yum Repository
1. Download MySQL's yum repository source
Here are downloaded to the /opt
directory, using the root
user, change based on actual usage
cd /opt
sudo wget https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
2. Install yum source
sudo rpm -ivh mysql80-community-release-el8-1.noarch.rpm
3. Install MySQL
sudo yum install mysql-community-server
[Note] If the server version of CentOS is installed without a password when MySQL is installed, the desktop version can enter the password.
4. Start the MySQL server
Start the service:
sudo service mysqld start
# 或 (CentOS 7 或 CentOS 8 推荐下面的命令)
sudo systemctl start mysqld.service
View the status of the server:
sudo service mysqld status
# 或 (CentOS 7 或 CentOS 8 推荐下面的命令)
sudo systemctl status mysqld.service
5. Log in to the database
After the installation is complete root
the password 空密码
, you can view the log from the installation.
[Note] 请注意与上一版本 5.7 的区别,5.7 会在日志中生成 root 用户的随机密码,但是 8 版本目前不会生成,以后应该会有,毕竟官网目前说的是(截止到 MySQL 5.7 为止)
.
less /var/log/mysql/mysqld.log
If the current system login user root
can directly use the following commands to quickly landed, equivalent to mysql -uroot --skip-password
, because there is no root password, so you do not need to use the sudo mysql -uroot -p
command, if you use this command, you need to enter a password when directly enter.
#输入 mysql 直接回车即可
mysql
[Note] mysql_secure_installation
command only MySQL 5.6
valid from MySQL 5.7
the beginning has been not be used.
6. Modify the root password
Use mysql
landing, and then modify root
the password:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
#输入 quit; 退出 mysql
mysql> quit;
Then again direct input mysql
is not allowed to log in, because we have to root
set a password, you need to log in via password to.
mysql -uroot -p
Enter password: # 输入设置的密码并回车
Congratulations! Then MySQL is installed!