CentOS 8 server install MySQL 8.0

Reference: MySQL official-A Quick Guide to Using the MySQL Yum Repository

1. Download MySQL's yum repository source

Here are downloaded to the /optdirectory, using the rootuser, 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 rootthe 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

Insert picture description here

If the current system login user rootcan 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 -pcommand, if you use this command, you need to enter a password when directly enter.

#输入 mysql 直接回车即可
mysql

[Note] mysql_secure_installationcommand only MySQL 5.6valid from MySQL 5.7the beginning has been not be used.

6. Modify the root password

Use mysqllanding, and then modify rootthe password:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

#输入 quit; 退出 mysql 
mysql> quit;

Then again direct input mysqlis not allowed to log in, because we have to rootset a password, you need to log in via password to.

mysql -uroot -p
Enter password:  # 输入设置的密码并回车

Congratulations! Then MySQL is installed!

Guess you like

Origin blog.csdn.net/peng2hui1314/article/details/107537639