1.centos7 How to install MySQL
============================================================================================
The installation steps are as follows:
1. First verify that the system has MySQL or mariadb installed
Rpm-qa | grep MySQL
Rpm-qa | grep MariaDB
2. If there is a relevant installation package, uninstall it immediately
RPM-E--nodeps Installation package name
such as: Rpm-e--nodeps mysql-community-client-5.1.18-1.el7.i686
Note: Be sure to uninstall the MARIADB package and your own MySQL package, or the installation will cause a variety of wonderful errors, resulting in failure.
3. Go to the official website https://dev.mysql.com/downloads/mysql/download the corresponding version of MySQL.
My CentOS7 is 32-bit, so I chose Red Hat Enterprise Linux 7/oracle Linux 7 (x86,32-bit).
Minimum installation download four files to:
mysql-community-common-5.7.19-1.el7.i686.rpm
mysql-community-libs-5.7.19-1.el7.i686.rpm
mysql-community-client-5.7.19-1.el7.i686.rpm
mysql-community-server-5.7.19-1.el7.i686.rpm
4. Installation sequence:
RPM-IVH mysql-community-common-5.7.19-1.el7.i686.rpm
RPM-IVH mysql-community-libs-5.7.19-1.el7.i686.rpm
RPM-IVH mysql-community-client-5.7.19-1.el7.i686.rpm
RPM-IVH mysql-community-server-5.7.19-1.el7.i686.rpm
Note: Common, Libs relies on common,client Libs,server relies on common and client.
5. Check the installation directory
Execute Whereis MySQL appears following the message stating that the installation was successful.
MySQL:/usr/bin/mysql/usr/lib/mysql/usr/share/mysql/usr/share/man/man1/mysql.1.gz
6. Check the MySQL configuration file
Vi/etc/my.cnf
The main content is as follows, generally do not need to change, the default value can be.
[Mysqld]
Datadir=/var/lib/mysql
Socket=/var/lib/mysql/mysql.sock
Symbolic-links=0
Log-error=/var/log/mysqld.log
Pid-file=/var/run/mysqld/mysqld.pid
7. Check directory permissions:
Be sure that DataDir sets the path for all groups and owners to be MySQL, and if not, run the following command change if not Gerze initialization fails.
Chown Mysql:mysql-r/var/lib/mysql
8. Close the service:
If the MySQL service is turned on, turn it off
Service Mysqld Stop
9. Here is the point: be sure to perform initialization!
Mysqld--initialize-insecure--user=mysql
Note: Be sure to add-insecure, so MySQL will create a root account without a password, otherwise it will create a password, the password will be written in/var/log/mysqld.log.
10. Open the service:
Service mysqld Start
11. Login account:
If you create a root account without a password, the direct MySQL return will enter MySQL.
Otherwise mysql-u root-p, enter the password.
At this point, the root account of MySQL can log in to the local MySQL, but the default does not support remote logins, the following is how to make the root account telnet process:
12. Using the database MySQL
Use MySQL;
13. Query Root account information
SELECT * from user \g;
This will see that the root account does not have a password, then we add a password to it, the root account without the password is not allowed to telnet.
14. Change the password of the root account:
Two global parameters must be modified:
Set global validate_password_policy=0;
Set global validate_password_length=1;
Update user set Aurhentication_string=password (' Your PASSWORD ') where user= ' root ';
Note: The new version of MySQL 5.7.15 need the above modification, because the field changed to Aurhentication_string, the online bad street that can not be used.
15.commit Permission changes:
Be sure to execute the following statement, otherwise the change password does not take effect.
Flush privileges;
16. Confirm that the password has been modified successfully:
Exit Quit MySQL
And then
Mysql-u root-p
Enter password
17. Log in to the root account after successful login
GRANT all privileges on * * to ' root ' @ '% ' identified by ' your password ' with GRANT OPTION;
Flush privileges;
Note:% means that any machine can be remote MySQL, if you turn% into an IP, you can specify a machine to log in remotely.
18. Try remote login:
Find a client, enter the relevant information
Host name or ip:******
Port: 3306
User name: Root
Password: your password
=====================================================================================
2.mysql password forgot, how to do?
====================================================================================
The process is as follows:
1.vi/etc/my.cnf
2. Add in [mysqld]
Skip-grant-tables
For example:
[Mysqld]
Skip-grant-tables
Datadir=/var/lib/mysql
Socket=/var/lib/mysql/mysql.sock
3. Restart MySQL
Service MySQL Restart
4. User Login without password
Mysql-uroot-p (Direct click to enter, password is empty)
5. Select a database
Use MySQL;
6. Change the root password
Update user set Authentication_string=password (' 123456 ') where user= ' root ';
7. Implementation
Flush privileges;
8. Exit
Exit
9. Delete
Skip-grant-tables
10. Restart MySQL
Service MySQL Restart
Installing mysql5.7 under CentOS