(1) Check the Linux version to download the corresponding mysql.
[View Linux information:] uname -a
(2) Check whether mysql has been installed.
[Check whether mysql is installed]
rpm -qa | grep -i mysql If installed, the relevant package name will be output
[If mysql has been installed, delete related files]
rpm -e [–nodeps] package name (where the package name is the name found by the above command)
(1) Official website address
[Official website address:]
https://downloads.mysql.com/archives/community/
https://downloads.mysql.com/archives/get/p/23/file/mysql-community-libs-8.0.11-1.el7.x86_64.rpm
https://downloads.mysql.com/archives/get/p/23/file/mysql-community-common-8.0.11-1.el7.x86_64.rpm
https://downloads.mysql.com/archives/get/p/23/file/mysql-community-server-8.0.11-1.el7.x86_64.rpm
https://downloads.mysql.com/archives/get/p/23/file/mysql-community-client-8.0.11-1.el7.x86_64.rpm
(2) Choose the right version
【Choose the right rpm package】
mysql-community-common-8.0.11-1.el7.x86_64.rpm
mysql-community-libs-8.0.11-1.el7.x86_64.rpm
mysql-community-server-8.0.11-1.el7.x86_64.rpm
mysql-community-client-8.0.11-1.el7.x86_64.rpm
Use xFtp6 to transfer the downloaded file from the windows system to the Linux system (optional operation, you can download it directly on Linux).
(1) Step1: Execute the installation command
rpm -ivh package name
[Installation sequence: (packages depend on each other, so you must pay attention to the installation sequence)]
Install common first
Reinstall libs (make sure that mariadb has been uninstalled, centos7 supports mariadb by default, does not support mysql, there will be conflicts if it is not uninstalled)
Reinstall client
Finally install the server
[ root@localhost opt]# rpm -ivh mysql-community-common-8.0.11-1.el7.x86_64.rpm
[ root@localhost opt]# rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64
[ root@localhost opt]# rpm -ivh mysql-community-libs-8.0.11-1.el7.x86_64.rpm
[ root@localhost opt]# rpm -ivh mysql-community-client-8.0.11-1.el7.x86_64.rpm
[ root@localhost opt]# rpm -ivh mysql-community-server-8.0.11-1.el7.x86_64.rpm
(2) Step2: Check whether the installation is successful
【method one:】
After mysql is successfully installed, the mysql user and user group will be created automatically.
cat /etc/passwd | grep mysql
cat /etc/group | grep mysql
【Method 2:】
mysqladmin –version
(1) Step1: Check whether the current service is started
【method one:】
ps -ef | grep mysql
【Method 2:】
service mysqld stauts
(2) Step2: Start and stop the mysql service
[Start mysql service:]
service mysql start
[Close mysql service: (optional operation)]
service mysql stop
An error was reported when connecting to the database for the first time.
【First login:】
mysql
[If an error message is prompted: (indicating a password is required)]
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)
(1) Solution 1: Check the initial password and log in with it.
[Solution 1: (Check the initial password for login)]
cat /var/log/mysqld.log | grep password
(2) Solution two:
[Solution 2: (Edit my.cnf file to skip the password)]
Find the mysql configuration file (end with .cnf).
find / -name “*/.cnf”
or:
mysql –help |grep -A 1 ‘Default options’
Edit the configuration file (my.cnf), find [mysqld], and add
skip-grant-tables # Used to skip password login
Restart the service:
service mysqld restart
No password required for login:
mysql
Through the above two methods, you can enter mysql, but the password is the initial password, or there is no password, which is definitely difficult to operate. A custom password is required.
(1) Set the login password and connect to the database again.
【set password:】
mysql> ALTER USER root@localhost IDENTIFIED BY ‘123456’;
[If there is an error:]
ERROR 1290 (HY000): The MySQL server is running with the –skip-grant-tables option so it cannot execute this statement
[Solution: (Execute the following statement)]
mysql> flush privileges;
mysql> ALTER USER root@localhost IDENTIFIED BY ‘123456’;
[Login again]
mysql -uroot -p
(2) After setting the initial password, you need to edit /etc/my.cnf
, and remove the skip-grant-tables
added before.
Restart the service.
[ root@localhost /]# vim /etc/my.cnf
[ root@localhost /]# service mysqld restart
Recommended Posts