Install and configure mysql5.6 and centos7mysql5.6 in Centos7
Centos7 replaces the default database mysql with Mariadb, which is not good news for those of us who want to use mysql.
Recently I have collected various installation tutorials on the Internet. If there are any problems, either installation fails or installation is successful, but mysql cannot be used. I finally finished my work today, so I 'd like to share it with you. Let's get started!
-------------------------------------------
1. Install MySQL
1、download installation package mysql-advanced-5.6.24-linux-glibc2.5-x86_64.tar.gz
|
Http://yunpan.cn/cFZhPVZ8gstJX (if you can not directly click to download, can be copied to the browser address bar to download) |
Extract Password |
6a8b |
2. Uninstall the built-in Mariadb.
[Root @ localhost ~] # Rmp-qa | grep mariadb // query the installed mariadb [root @ localhost ~] # Pm-e -- nodeps file name // unmount one by one
3. Delete the my. cnf file under the etc directory.
[root@localhost~]# rm /etc/my.cnf
4. Run the following command to create a mysql user group.
[root@localhost~]# groupadd mysql
5. Run the following command to create a user named mysql and join the mysql user group.
[root@localhost ~]# useradd -g mysql mysql
6. Put the downloaded binary compressed package in the/usr/local/directory.
7. Unzip the installation package
[root@localhost ~]# tar -zxvf mysql-advanced-5.6.24-linux-glibc2.5-x86_64.tar.gz
8. Rename the decompressed folder to mysql.
9. Create the configuration file my. cnf under etc and add the following code to the file:
[Mysql] # set the default character set of the mysql client default-character-set = utf8 socket =/var/lib/mysql. sock [mysqld] skip-name-resolve # Set port 3306 port = 3306 socket =/var/lib/mysql. sock # Set the mysql installation directory basedir =/usr/local/mysql # Set the data storage directory of the mysql database datadir =/usr/local/mysql/data # maximum number of connections allowed max_connections = 200 # The default character set used by the server is the 8-bit latin1 character set character-set-server = utf8 # default storage engine default-storage-engine = INNODB lower_case_table_names = 1max_allowed_packet = 16 M
10. Go to the mysql installation directory.
[Root @ localhost ~] # Cd/usr/local/mysql [root @ localhost mysql] # chown-R mysql: mysql. /change the current directory owner to mysql user [root @ localhost mysql] #. /scripts/mysql_install_db -- user = mysql installation database [root @ localhost mysql] # chown-R mysql: mysql data modifies the current data directory owner as a mysql user
The database has been installed!
Ii. Configure MySQL
1. Grant my. cnf the maximum permission.
[root@localhost ~]# chown 777 /etc/my.cnf
Set the Automatic startup Service Control script:
2. Copy the startup script to the Resource Directory.
[root@localhost mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
3. added the mysqld service control script execution permission.
[root@localhost mysql]# chmod +x /etc/rc.d/init.d/mysqld
4. Add the mysqld service to the System Service
[root@localhost mysql]# chkconfig --add mysqld
5. Check whether the mysqld service has taken effect.
[root@localhost mysql]# chkconfig --list mysqld
Command output is similar to the following result:
Mysqld 0: off 1: off 2: on 3: on 4: on 5: on 6: off
It indicates that the mysqld service has taken effect and is automatically started at the 2, 3, 4, and 5 running levels as the system starts. In the future, you can use the service command to control the start and stop of mysql.
6. Start msql (stop mysqld service: service mysqld stop)
[root@localhost mysql]# service mysqld start
7. Add the bin directory of mysql to the path environment variable and edit the/etc/profile file.
[root@localhost mysql]# vi /etc/profile
Add the following information at the end of the file:
[root@localhost mysql]# export PATH=$PATH:/usr/local/mysql/bin
Run the following command to make the changes take effect:
[root@localhost mysql]# . /etc/profile
8. log on to mysql as a root account. The default logon password is no.
[root@localhost mysql]# mysql -u root -p
9. Set the password for the root account. Note the following: change your password to your password.
[root@localhost mysql]# use mysql
[root@localhost mysql]# update user set password=password('you password') where user='root' and host='localhost';
10. Set Remote Host Logon (Navicat is used). Note that the following your username and your password are changed to the user and password you need to set.
[root@localhost mysql]# GRANT ALL PRIVILEGES ON *.* TO 'your username'@'%' IDENTIFIED BY 'your password' WITH GRANT OPTION;
The copyright of this article is shared by the author and the blog. You are welcome to repost it, but you must keep this statement and provide the original article link. Thank you for your cooperation!