Install mysql

rpm -qa|grep -i mysql
Copy the code

Uninstall the existing mysql

rpm -ev --nodeps mysql80-community-release-el8-1.noarch rpm -ev --nodeps Mysql - common - 8.0.21-1. Module_el8. 2.0 + 493 + 63 b41e36 x86_64 RPM - ev -- nodeps Mysql - errmsg - 8.0.21-1. Module_el8. 2.0 + 493 + 63 b41e36 x86_64 RPM - ev -- nodeps The mysql server - 8.0.21-1. Module_el8. 2.0 + 493 + 63 b41e36 x86_64 RPM - ev -- nodeps Mysql - 8.0.21-1. Module_el8. 2.0 + 493 + 63 b41e36 x86_64Copy the code

After executing the command executed again RPM – qa | grep -i have done uninstall mysql will find.

Download and install MySQLmysql

wget http://repo.mysql.com/mysql80-community-release-el8-1.noarch.rpm
rpm -ivh mysql80-community-release-el8-1.noarch.rpm
yum update
yum install mysql-server
Copy the code

Initialize MySQL;

mysqld --initialize --console
Copy the code

Permission Settings:

chown mysql:mysql -R /var/lib/mysql
Copy the code

Start the MySQL:

systemctl start mysqld
Copy the code

Check the MySQL running status:

systemctl status mysqld
Copy the code

Change the password of user root to mysql8

  • Add skip-grant-table under mysqld to /etc/my. CNF
vim /etc/my.cnf
Copy the code

  • Restart the service, and then you can log in to mysql without secret
# systemctl restart mysqld
# mysql -u root -p
Copy the code
  • Enter the command and press Enter to enter mysql.

  • Change the password of user root and exit the system. If there is content in the authentication_STRING (must be empty for the first time) field of user root, set it to empty. Otherwise, go to step 2.
# use mysql;
# update user set authentication_string='' where user='root';
# exit;
Copy the code

  • CNF /etc/my. CNF/skip-grant-table Restart the mysql service.

# /etc/my.cnf
# systemctl restart mysqld
Copy the code
  • Run the ALTER command to change the password of user root by running the mysqladmin -u root password “******” command. As follows:
mysqladmin -u root password "******"
Copy the code

Log in using the new password

mysql -u root -p
Copy the code

Enter a new password password, enter.

Note: If we are starting the mysql service for the first time, the mysql server will be initialized first.

Alternatively, you can use MariaDB instead. MariaDB database management system is a branch of MySQL, maintained primarily by the open source community and licensed under the GPL. One reason for the development of the branch was that the community took the branch approach to avoid the potential risk of closing MySQL after Oracle acquired it. MariaDB is intended to be fully compatible with MySQL, including apis and command lines, making it an easy replacement for MySQL.

yum install mariadb-server mariadb

The mariadb database commands are:

  • Systemctl start mariadb #
  • Systemctl stop mariadb #
  • Systemctl restart mariadb #
  • Systemctl enable mariadb #

Verify MySQL installation

After a successful MySQL installation, some basic tables are initialized, and after the server is started, you can perform a simple test to verify that MySQL is working properly.

Use the mysqladmin tool to get the server status:

Use the mysqladmin command to check the version of the server. On Linux, the binary is in the /usr/bin directory and on Windows, the binary is in C:\mysql\bin.

[root@host]# mysqladmin --version
Copy the code

On Linux this command will output the following results, based on your system information:

Mysqladmin Ver 8.0.21 for Linux on x86_64 (Source distribution)Copy the code

If no information is displayed after the preceding command is executed, it indicates that Mysql is not installed successfully.

Use MySQL Client to execute simple SQL commands

You can connect to the MySQL server using the MySQL command from the MySQL Client. By default, the MySQL server login password is empty, so this example does not need to enter a password.

The command is as follows:

[root@host]# mysql
Copy the code

Mysql > connect to mysql server