Install mysql5.6 and centos7mysql5.6 on CentOS7

Source: Internet
Author: User
Tags localhost mysql

Install mysql5.6 and centos7mysql5.6 on CentOS7

There will always be some minor problems during MySQL installation, resulting in slow installation progress. add your own actual operations to Baidu search, summarize the installation methods, and make common progress.

1. Install mysql

1. Download the installation package and install it using the wget command.

wget -c -t0 https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz

2. Uninstall the built-in Mariadb.

[Root @ localhost ~] # Rpm-qa | grep mariadb // query the installed mariadb [root @ localhost ~] # Rpm-e -- nodeps file name // uninstall mariadb. The file name is the file queried by the preceding command.

3. delete my. cnf 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 compressed package in the/usr/local/directory (the file to be moved through the mv/usr/local /)

7. Unzip the installation package

[root@localhost ~]# tar -xvf mysql-5.6.34-linux-glibc2.5-x86_64.tar

Note: If the compressed package is: mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz

Decompress the command to: tar-zxvf mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz

8. Rename the decompressed folder to mysql.

[Root @ localhost local] # mysql folder name extracted from mv

9. Create the configuration file my. cnf under etc and add the code to the file:

Copy the my-default.cnf file under the/usr/local/mysql/support-files path to/etc/my. cnf and name it my. cnf

[root@localhost support-files]# cp my-default.cnf /etc/my.cnf 

Configure the my. cnf file in the/etc directory

[root@localhost support-files]# vim /etc/my.cnf

Use the vim editor to edit the my. cnf Code as follows: you can find the corresponding configuration on the Internet.

[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 18. character-set-server = utf8 # default storage engine default-storage-engine = INNODB lower_case_table_name = 1 max_allowed_packet = 16 M used to create a new table

10. Go to the mysql installation directory.

[Root @ localhost ~] # Cd/usr/local/mysql [root @ localhost mysql] # chown-R mysql: mysql. /modify the current directory as a mysql user [root @ localhost mysql] #. /scripts/mysql_install_db -- user = mysql -- basedir =/usr/local/mysql/-- datadir =/usr/local/mysql/data/install the database

Note: If the last command is executed, the following problem occurs:

FATAL ERROR: please install the following Perl modules before executing   ./scripts/mysql_install_db:Data::Dumper

Solution: Install the autoconf library.

Command: yum-y install autoconf // this package will install Data: Dumper module after installation is complete re-execute the above installation database

Note: If the following error occurs during database installation

2018-03-19 14:00:43 40502 [ERROR] /usr/local/mysql//bin/mysqld: unknown variable 'l_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES'2018-03-19 14:00:43 40502 [ERROR] Aborting

Solution: comment out the following sentence in the/etc/my. cnf file.

[Root @ localhost mysql] # vim/etc/my. cnfl_mode = NO_ENGINE_SUBSTITUTION, STRICT_TRANS_TABLES // comment out #

Re-Execute Database Installation

Change the owner of the current data directory to a mysql user.

[root@localhost mysql]# chown -R mysql:mysql data

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 
Note: The output result only shows the SysV service and does not contain the native systemd service. The SysV configuration data may be overwritten by the native systemd configuration. To list the systemd service, run 'systemctl list-unit-files '. To view the services enabled for a specific target, run 'systemctl list-dependencies [target] '. Mysqld 0: off 1: off 2: open 3: Open 4: Open 5: Open 6: Off

Service Command Control mysql Start and Stop

Command: service mysqld start and service mysqld stop

6. Start mysqld

 [root@localhost mysql]# service mysqld start

Note: Exceptions occur after startup.

 

Solution

Create a folder [root @ localhost lib] # mkdir/var/lib/mysql grant the folder permission chmod 777/var/lib/mysql

7. Add the bin directory of mysql to the path environment variable and edit ~ /. Bash_profile File

[root@localhost mysql]# vim ~/.bash_profile  

Add the following information at the end of the file: specify the location of the Environment Variable Startup Program

export PATH=$PATH:/usr/local/mysql/bin 

Run the following command to make the modified content effective immediately:

[root@localhost mysql]# source ~/.bash_profile

8. Use the root account to log on to mysql. By default, there is no password. You can press Enter when entering the password.

[root@localhost mysql]# mysql -u root -p

9. Set the root account password to root (you can also change it to the password you want)

mysql>use mysql  mysql>update user set password=password('root') where user='root' and host='localhost';  mysql>flush privileges;  

10. Set Remote Host Logon. Run the following command to view and add the logon password. Note that you need to change the following your username and your password to the user and password you need to set.

View User select Host, User, Password from mysql. user; create user test identified by '000000'; grant all privileges on *. * to 'test' @ '%' identified by '000000' with grant option; refresh flush privileges; modify the specified user password to update mysql. user set password = password ('new password') where User = "test" and Host = "localhost "; delete user delete from User where user = 'test' and Host = 'localhost ';

If not, set the CentOS7 firewall.

Check whether open ports (no ports are opened by default) are enabled on firewall-cmd -- list-ports! Query port number: firewall-cmd -- query-port = 8020/tcp enable port 80 firewall-cmd -- zone = public (Scope) -- add-port = 80/tcp (port and access type) -- permanent (effective permanently) Restart firewall-cmd -- reload stop firewall systemctl stop firewalld. disable the firewall from starting systemctl disable firewalld. service delete firewall-cmd -- zone = public -- remove-port = 80/tcp -- permanent

Other versions: seeHttp://blog.csdn.net/wailaizhu/article/details/53488954

Modify vim/etc/sysconfig/iptables
Add port number
-A input-m state -- state NEW-m tcp-p tcp -- dport 80-j ACCEPT or add Port Access
1. 80, 22, port 8080/sbin/iptables-I input-p tcp -- dport 80-j ACCEPT/sbin/iptables-I input-p tcp -- dport 22-j ACCEPT/sbin/iptables-I INPUT-p tcp -- dport 8080-j ACCEPT2. save/etc/rc. d/init. d/iptables save3. view the opened port/etc/init. d/iptables status4. disable the firewall. 1) it will take effect permanently and will not be enabled after restart: chkconfig iptables on Disabled: chkconfig iptables off2) it will take effect immediately. Restart and restart: service iptables start disabled: service iptables stop

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.