Unloading
First, delete the old version of MySQL related
One. See if MySQL is installed on the server
- To see if there are any installation packages:
Rpm-qa|grep MySQL
Yum List mysql*
- Remove older MySQL-related software
Yum remove MySQL mysql-server mysql-libs compat-mysql51
Rm-rf/var/lib/mysql
Rm/etc/my.cnf
Download MySQL
# # # #下载rpm安装包 # #
1. Configure the Yum source
Download the Yum source RPM installation package on the MySQL website: https://dev.mysql.com/downloads/repo/yum/
Download MySQL Source installation package
shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
Install MySQL source
shell> Yum Localinstall mysql57-community-release-el7-8.noarch.rpm
Check that the MySQL source is installed successfully shell> Yum Repolist enabled | grep "MySQL. -community."
[email protected] ~]# Yum Repolist enabled | grep "MySQL. -community."
Mysql-connectors-community/x86_64 MySQL Connectors Community 51
mysql-tools-community/x86_64 MySQL Tools Community 63
mysql57-community/x86_64 MySQL 5.7 Community Server 267
See shown indicates successful installation.
Installation
2. Install MySQL
shell> Yum Install Mysql-community-server
3. Start the MySQL service
Shell> systemctl Start mysqld
To view the startup status of MySQL
shell> systemctl Status Mysqld
[Email protected] ~]# systemctl status mysqld
Mysqld.service-mysql Server
Loaded:loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset:disabled)
Active:active (running) since Mon 2018-05-07 14:36:16 UTC; 11min ago
Docs:man:mysqld (8)
Http://dev.mysql.com/doc/refman/en/using-systemd.html
Main pid:36800 (mysqld)
CGroup:/system.slice/mysqld.service
└─36800/usr/sbin/mysqld--daemonize--pid-file=/var/run/mysqld/mysqld.pid
May 14:36:03 localhost systemd[1]: Starting MySQL Server ...
May 14:36:16 localhost systemd[1]: Started MySQL Server.
4. Boot start
Shell> Systemctl Enable mysqld
Shell> Systemctl Daemon-reload
See if the boot setting is successful
Chkconfig--list | grep mysql*
Mysqld 0: Off 1: Off 2: Enable 3: Enable 4: Enable 5: Enable 6: Off stop
- Log in to MySQL
Mysql-u root-p
#如果忘记密码解决, review the following questions
7. Modify the root local login password
After the MySQL installation is complete, a default password is generated for root in the/var/log/mysqld.log file. Locate the root default password in the following way, and then log in to MySQL to modify it:
shell> grep ' temporary password '/var/log/mysqld.log
Shell> Mysql-u Root-p
Mysql> ALTER USER ' root ' @ ' localhost ' identified by ' mynewpass4! ';
Or
After entering MySQL We first modify the login password "
mysql> set password for ' root ' @ ' localhost ' =password (' 123qaz! ');
The new password is written in parentheses.
Note: mysql5.7 The password security check plug-in (Validate_password) is installed by default, and the default password check policy requires that the password must contain: uppercase and lowercase letters, numbers, and special symbols, and not less than 8 bits in length. Otherwise you will be prompted for error 1819 (HY000): Your password does not satisfy the current policy requirements error as shown:
You can view information about the password policy through the MSYQL environment variable:
Mysql> Show variables like '%password% ';
MySQL official website Password Policy detailed description: Http://dev.mysql.com/doc/refman/5.7/en/validate-password-options-variables.html#sysvar_ Validate_password_policy
Modify Password Policy
Add validate_password_policy configuration in/etc/my.cnf file, specify password policy
Choose 0 (Low), 1 (MEDIUM), 2 (Strong) One, select 2 to provide a password dictionary file
Validate_password_policy=0
If you do not require a password policy, add the following configuration to disable the My.cnf file:
Validate_password = Off
Restarting the MySQL service causes the configuration to take effect:
Systemctl Restart Mysqld
Default configuration file path:
Configuration file:/etc/my.cnf
Log file:/var/log//var/log/mysqld.log
Service startup script:/usr/lib/systemd/system/mysqld.service
Socket file:/var/run/mysqld/mysqld.pid
############### #重置mysql密码 ##################
If you forget the root password, restore it as follows:
Systemctl stop MySQL #关闭mysql服务
Find/-name my*.cnf #查找my. CNF configuration file (locate My.cnf file)
Add one sentence to the paragraph in [mysqld]: Skip-grant-tables Save and Exit VI.
Systemctl start MySQL # #启用mysql服务
Mysql-u Root
Update Mysql.user set Authentication_string=password (' 123qwe ') where user= ' root ' and Host = ' localhost ';
or (update mysql.user set Password=password (' Password ') where user= ' root ';)
Flush privileges;
Exit
Systemctl restart MySQL #重启mysql服务
1. View the initialization password:
[[email protected] ~]# grep ' temporary password '/var/log/mysqld.log
Change Password
mysql> alter user [email protected] identified by ' xxx ';
New password requirements, must contain uppercase and lowercase alphanumeric and symbols.
Turn off password complexity verification:
Add Validate_password=off in MY.CNF
</apj1+mshge
</apj1+mshge
############################################
Remote access port number for open firewall MySQL
1. Add Permissions
The user table in the MySQL library has a new record of "%" and "root" for user
- Several important directories for Linux MySQL
Database Directory/var/lib/mysql/
Configuration file/usr/share/mysql (mysql.server command and configuration file)
Related Commands/usr/bin (mysqladmin mysqldump, etc.)
Startup script/etc/rc.d/init.d/(startup script file for MySQL directory)
6. Delete MySQL Database
#如果使用的是yum安装的mysql, if you want to delete it, use the following command:
Yum-y Remove mysql*
Then remove all files under the/var/lib/mysql folder and then re-perform the installation steps above
7. Authorized User from remote login
Note: The following two steps need to be performed. Step one, just modify the user's password. However, the user is not authorized; Step two is authorization, allowing the user to specify permissions (connect to database, query database ...)
- Change the table method. It may be that your account is not allowed to log on remotely, only on localhost. This time, as long as the computer on the localhost, log in to MySQL, change the "MySQL" Database in the "User" table "host", from "localhost" to "%"
Mysql-u Root-pvmware;
Mysql>use MySQL;
Mysql>update User Set host = '% ' where user = ' root ';
Mysql>select host, user from user;
- Authorization law. For example, if you want to myuser use MyPassword to connect to a MySQL server from any host.
GRANT all privileges on . To ' myuser ' @ '% ' identified by ' MyPassword ' with GRANT OPTION;
If you want to allow users to connect to the MySQL server from a host myuser IP 192.168.1.3 and use MyPassword as the password
GRANT all privileges on . To ' myuser ' @ ' 192.168.1.3 ' identified by ' MyPassword ' with GRANT OPTION;
8. Note
Attention:
1. "The following sentence must be executed, or you will not be able to log in"
Mysql>flush privileges;
2. If the user is unable to log in from the local, this time do the following
GRANT all privileges on . To ' root ' @ ' Localhost.localdomain ' identified by ' 123456 ' with GRANT OPTION;
Flush privileges;
################################################
Note: The firewall must remember to shut down, otherwise it is not remotely connected
LINUX7 shutting down the firewall:
1. View firewall status: Systemctl status Firewalld
2. Check if the boot Firewall service is started: Systemctl is-enabled firewalld
3. Close and view firewall: Systemctl stop firewalld/systemctl status Firewalld
4. Disable the firewall (boot does not start) systemctl disable Firewalld/systemctl is-enabled firewalld
################### #初始化多实例数据库 #######################
1) 5.1.X Initialization command: (Mysql.bin)
mysql_install_db--basedir=/application/mysql--datadir=/data/3306/data--user=mysql
mysql_install_db--basedir=/application/mysql--datadir=/data/3307/data--user=mysql
2) 5.5.32 Initialization command: (cd/application/mysql/scripts)
./mysql_install_db--basedir=/application/mysql--datadir=/data/3306/data--user=mysql
./mysql_install_db--basedir=/application/mysql--datadir=/data/3307/data--user=mysql
MySQL Installation and uninstallation