Install MySQL5.6.22 in CentOS-7, centos install mysql5.6

Source: Internet
Author: User
Tags windows x86

Install MySQL5.6.22 in CentOS-7, centos install mysql5.6

Install MySQL5.6.22 in CentOS7 (Latest Version)

Reprinted please indicate the source:Jiq • Chin's technical Blog

1. installation environment

(1) CentOS version: CentOS-7

View method:

[Root @ bogon desktop] # cat/etc/redhat-release

CentOS Linux release 7.0.1406 (Core)

Source: download from the official website

: Http://www.centos.org/

MySQL edition: MySQL-5.6.22

Source: download from the official website

: Https://edelivery.oracle.com/EPD/Search/handle_go

Or http://pan.baidu.com/s/1dDu6n9R

Name: MySQL Database 5.6.22 RPM for Oracle Linux/RHEL 7x86 (64bit)

2. Installation Method Selection

I searched on the Internet and found that there are three ways to install MYSQL in Linux:

1. download and install the SDK online using the yum command

2. Download the offline rpm installation package

3. Download the source code for compilation and Installation

Method 1 is not intended to be used, because most of our project servers cannot directly access the Internet, and there are many online installation tutorials. Method 3 is unnecessary for anyone who applies MYSQL, however, there is a good website for your reference: http://www.ecstoredev.com/webserver/linux/centos7-mysql-5-6-10.html. I select option 2.

Step 3

1. decompress the downloaded zip package and you will find the following rpm packages:

MySQL-client-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-devel-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-embedded-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-server-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-shared-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-shared-compat-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-test-advanced-5.6.22-1.el7.x86_64.rpm

 

2. Uninstall MariaDB

If you click "rpm package installation", an error is returned. Because the default CentOS database is no longer MySQL, but MariaDB, why?

The MariaDB database management system is a branch of MySQL. It is mainly maintained by the open-source community and licensed by GPL. One of the reasons for developing this branch is that after Oracle acquired MySQL, there is a potential risk of closing the source of MySQL. Therefore, the community uses the branch method to avoid this risk. MariaDB is designed to be fully compatible with MySQL, including APIs and command lines, so that it can easily become a substitute for MySQL.

View the currently installed mariadb package:

[Root @ bogon desktop] # rpm-qa | grep mariadb

Unmount them all forcibly:

[Root @ bogon desktop] # rpm-e-nodeps mariadb-libs-5.5.35-3.el7.x86_64

[Root @ bogon desktop] # rpm-e-nodeps mariadb-5.5.35-3.el7.x86_64

[Root @ bogon desktop] # rpm-e-nodeps mariadb-server-5.5.35-3.el7.x86_64

 

3. Install MYSQL

Double-click the following three packages for automatic installation:

MySQL-client-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-devel-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-server-advanced-5.6.22-1.el7.x86_64.rpm

Tip: Actually, I don't know what the second package devel is, and I don't know if it is necessary (it should not be necessary to search online ), if no test is required, you have already installed it. You don't want to take the time to test whether it is required. If you have tested it, please leave a message to inform us.

 

4. Start MYSQL

[Root @ bogon desktop] # service mysql start

Error:ERROR! The server quit without updating PID file

From this website (address http://www.jb51.net/article/33810.htm) found that there are many possibilities of this error, such as a small problem in the configuration file will also cause this error, we here mainly because:Selinux is triggered by centos. selinux is enabled by default. The solution is to disable it, enable/etc/selinux/config, change SELINUX = enforcing to SELINUX = disabled, and then save the disk and restart the machine.

Then start mysql:

[Root @ bogon desktop] # service mysql start

View the MySQL running status:

[Root @ bogon desktop] # service mysql status

SUCCESS! MySQL running (2377)

 

5. By default, the root user logs on to MYSQL.

[Root @ bogon desktop] # mysql-u root-p

Enter password:

ERROR 1045 (28000): Access denied for user 'root' @ 'localhost' (using password: YES)

I found an error. I checked it online and used the following command to change the root initialization password:

[Root @ bogon desktop] #/usr/bin/mysqladmin-u root password 'passok'

/Usr/bin/mysqladmin: connect to server at 'localhost' failed

Error: 'accesssdenied for user' root' @ 'localhost' (using password: NO )'

The default root user of the MYSQL database still cannot set a password for Logon. You need to perform the following operations:

 

Reset and verify the root user password in MySQL

Or not, and then find another method to reset the root user password in MySQL and verify it on the Internet:

(1) Stop the MySQL Service

[Root @ bogon desktop] # service mysql stop

Shutting down MySQL... SUCCESS!

(2) enter the password bypass authentication command

[Root @ bogon desktop] # mysqld_safe -- user = mysql -- skip-grant-tables -- skip-networking &

[1] 5807

150117 22:23:31 mysqld_safe Logging to '/var/lib/mysql/bogon. err '.

150117 22:23:31 mysqld_safe Starting mysqlddaemon with databases from/var/lib/mysql

(3) enter the logon USER command

[Root @ bogon desktop] # mysql-u root mysql

Reading table information for completion oftable and column names

You can turn off this feature to get aquicker startup with-

Welcome to the MySQL monitor. Commands end with; or \ g.

Your MySQL connection id is 1

Server version: 5.6.22-enterprise-commercial cial-advanced MySQL Enterprise Server-AdvancedEdition (Commercial)

Copyright (c) 2000,201 4, Oracle and/or itsaffiliates. All rights reserved.

Oracle is a registered trademark of OracleCorporation and/or its

Affiliates. Other names may be trademarksof their respective

Owners.

Type 'help; 'or' \ H' for help. type' \ C' toclear the current input statement.

(4) enter the SQL statement for modifying the root password

Mysql> UPDATEuser SET Password = PASSWORD ('passok') where USER = 'root ';

Query OK, 4 rows affected (0.04 sec)

Rows matched: 4 Changed: 4 Warnings: 0

(5) enter the data refresh command

Mysql> FLUSHPRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

(6) Exit

Mysql> quit

Bye

(7) Start MYSQL

[Root @ bogon desktop] # service mysql start

Starting MySQL SUCCESS!

 

Log on to mysql and view all databases:

[Root @ bogon desktop] # mysql-u root-p

Mysql> show databases;

ERROR 1820 (HY000): You must set password before executing this statement

 

There is still an error, prompting you to set the password again:

Mysql> SETPASSWORD = PASSWORD ('passok ');

Query OK, 0 rows affected (0.00 sec)

Show database:

Mysql> show databases;

+ -------------------- +

| Database |

+ -------------------- +

| Information_schema |

| Mysql |

| Performance_schema |

| Test |

+ -------------------- +

4 rows in set (0.00 sec)

Go to the database to create and display tables:

Mysql> use test;

Database changed

Mysql> show tables;

Empty set (0.02 sec)

Mysql> create table testTable (name char (15) not null, passwd char (15) not null );

Query OK, 0 rows affected (0.87 sec)

Mysql> show tables;

+ ---------------- +

| Tables_in_test |

+ ---------------- +

| TestTable |

+ ---------------- +

1 row in set (0.00 sec)

 

Note:The password I set is "passok ". When You execute showdatabases, You will receive the ERROR "ERROR 1820 (HY000): You must set password before executing this statement". You can also try the following method to log on to mysql and run showdatabases to check whether this ERROR exists, I have no conditions for testing:

Log on to the MySQL page: mysql-uroot-p (new password modified)

Example: mysql-u root-p123456

 

Three main directories and functions after mysql installation:

/Var/lib/mysql database file

/Usr/share/mysql command and configuration file

/Usr/bin mysqladmin, mysqldump, and other commands

 

6. Use workbench on Windows 7 to connect to the remote MySQL Server

(1) download and install workbench (MySQL Workbench 6.2.4 MSI for Windows x86 (64bit ))

(2) Installing mysql workbench in Windows requires the following environment:

Microsoft. NET Framework 4 Client Profile

Microsoft Visual C ++ 2013 RedistributablePackage (x64)

Needless to say, the first one is in:

Http://www.microsoft.com/zh-CN/download/details.aspx? Id = 40784

(3) After the installation is complete, open and configure the connection:

Unable to connect.

Open the cmd command line and enter telnet 192.168.1.108 3306. The system also prompts that the connection fails (BTY: telnet is not installed in windows 7 by default. You need to enable or disable the telnet client function in the control panel ).

 

To remotely access the MYSQL database, you also need:

(1) grant the specified user the permission to access the mysql database remotely;

(2) configure the firewall to open the limit on port 3306;

 

1. Grant the specified user the permission to access the mysql database remotely.

The authorization command is:

Grant permission 1, permission 2 ,... Permission n on database name. Table name to user name @ user address identified by 'Password'

[Root @ bogon desktop] # mysql-uroot-ppassok-e "grant all privileges on *. * TO 'root' @ '% 'identified BY 'passok' with grant option ;"

Warning: Using a password on the commandline interface can be insecure.

Run the grant command as the root user (the-e parameter indicates executing an SQL command), meaning: assign all permissions for all tables in all databases to the root user at all IP addresses. If you only want to access the root user on the host 192.168.1.108, run the following command:

Mysql-uroot-ppassok-e "grant all privileges on *. * TO 'root' @ '192. 168.1.108 'identified by 'passok' with grant option ;"

 

2. configure the firewall to open port 3306

The firewall of CentOS 7.0 uses firewall by default, which is different from the previous version using iptables. After my test, as long as firewall is enabled, remote access to the MYSQL database is impossible.

First, disable firewall:

[Root @ bogon desktop] # systemctl stop firewalld. service # stop firewall

[Root @ bogon desktop] # systemctl disable firewalld. service # disable firewall startup

Although CentOS is not iptables by default, it has been installed. Then I configure the open rules for port 3306 according to the online method:

[Root @ bogon desktop] # vi/etc/sysconfig/iptables

# Sample configuration for iptables service

# You can edit this manually or usesystem-config-firewall

# Please do not ask us to add additionalports/services to this default configuration

* Filter

: Input accept [0: 0]

: Forward accept [0: 0]

: Output accept [0: 0]

-A input-m state -- stateRELATED, ESTABLISHED-j ACCEPT

-A input-p icmp-j ACCEPT

-A input-I lo-j ACCEPT

-ARH-Firewall-1-INPUT-m state -- state NEW-m tcp-p tcp -- dport 3306-j ACCEPT

-A input-p tcp-m state -- state NEW-m tcp -- dport 22-j ACCEPT

-A input-j REJECT -- reject-withicmp-host-prohibited

-A forward-j REJECT -- reject-withicmp-host-prohibited

COMMIT

 

Then restart the Firewall:

[Root @ bogon desktop] # service iptables restart

Then I immediately used mysql workbench for testing and found that I still couldn't connect.

 

Run the following command to permanently disable iptables:

[Root @ bogon bin] # chkconfig iptables off

Note: The request is being forwarded to "systemctl disable iptables. service ".

Then I immediately used mysql workbench for testing and found that I still couldn't connect.

 

Restart CentOS. The connection is successful.

It seems that a restart will take effect.

 

Further test:

Viewing the firewall Status is disabled:

[Root @ bogon bin] # service firewall status

Redirecting to/bin/systemctl status firewall. service

Firewall. service

Loaded: not-found (Reason: No such file or directory)

Active: inactive (dead)

 

Viewing the iptables status is also disabled:

[Root @ bogon bin] # service iptables status

Redirecting to/bin/systemctl status iptables. service

Iptables. service-IPv4 firewall withiptables

Loaded: loaded (/usr/lib/systemd/system/iptables. service; disabled)

Active: inactive (dead)

 

Then I started the iptables firewall again to still be able to access it. After I commented out all the rules in/etc/sysconfig/iptables, I still could access it and restart it. I don't know why, view the status of iptables is also active:

[Root @ bogonbin] # service iptables status

Redirecting to/bin/systemctl status iptables. service

Iptables. service-IPv4 firewall withiptables

Loaded: loaded (/usr/lib/systemd/system/iptables. service; disabled)

Active: active (exited) since 2015-01-1818: 17: 07 CST; 20 s ago

Process: 14440 ExecStop =/usr/libexec/iptables. init stop (code = exited, status = 0/SUCCESS)

Process: 14648 ExecStart =/usr/libexec/iptables. init start (code = exited, status = 0/SUCCESS)

MainPID: 14648 (code = exited, status = 0/SUCCESS)

 

January 18 18:17:07 bogoniptables. init [14648]: iptables: Applying firewall rules: [OK]

January 18 18:17:07 bogon1_emd [1]: Started IPv4 firewall with iptables.

You can disable the iptables firewall permanently, but remember to restart it.

 

7. Set mysql to boot automatically

Choose to use the chkconfig command to set the startup service. You can see that we use this command to permanently disable iptables. The command format is as follows:

Chkconfig Function Description: Check and set various services of the system.

Syntax: chkconfig [-- add] [-- del] [-- list] [System Service] Or chkconfig [-- level <level code>] [System Service] [on/off/reset]

-- Add service

-- Del Delete Service

-- List to view the startup status of each Service

 

After mysql is installed, it is automatically started upon startup by default:

[Root @ bogon desktop] # chkconfig -- list mysql

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] '.

Mysql 0: off 1: off 2: open 3: Open 4: Open 5: Open 6: Off

If it is not self-starting, use the command to enable the MySQL service to automatically enable it:

Chkconfig mysqld on

Chkconfig mysql on

 

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.