Background:
In CentOS 6.4, the installation of MySQL via Yum is version 5.1, older, so you want to install the high version of 5.6.22 via source code.
Body:
One: Uninstall the old version
Use the following command to check if MySQL Server is installed
Rpm-qa | grep MySQL
Some words are unloaded by the following command
RPM-E MySQL//normal Delete mode
RPM-E--nodeps MySQL//brute force Delete mode, if you use the above command to delete, prompted to have other dependent files, then use this command can be strongly deleted.
Two: Install MySQL
Install packages required for compiling code
Yum-y install make gcc-c++ cmake bison-devel ncurses-devel
Download MySQL 5.6.22
wget Http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.22.tar.gztar xvf mysql-5.6.14.tar.gzcd mysql-5.6.22
Compile and install (CMake)
CMake-dcmake_install_prefix=/usr/local/MySQL-dmysql_datadir=/usr/local/mysql/Data-dsysconfdir=/etc-dwith_myisam_storage_engine=1 -dwith_innobase_storage_engine=1 -dwith_memory_storage_engine=1 -dwith_readline=1 -dmysql_unix_addr=/var/lib/mysql/Mysql.sock-dmysql_tcp_port=3306 -denabled_local_infile=1 -dwith_partition_storage_engine=1 -dextra_charsets= All-ddefault_charset=UTF8-ddefault_collation=Utf8_general_cimake&& make Install
The compiled parameters can refer to http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html.
The whole process takes about 30 minutes ... A long wait
: Configure MySQL
Set permissions
Use the following command to see if there are MySQL users and user groups
CAT/ETC/PASSWD View user list Cat/etc/group View user Groups list
If not, create
Groupadd mysqluseradd-g MySQL MySQL
Modify/usr/local/mysql Permissions
Chown-r Mysql:mysql/usr/local/mysql
Modify/usr/local/mysql Permissions
Initialize configuration
Go to installation path
Cd/usr/local/mysql
Enter the installation path, execute the initialization configuration script, create the system's own database and table
scripts/mysql_install_db--basedir=/usr/local/mysql
--datadir=/usr/local/mysql/data--user=mysql
Note: After the minimum installation of the CentOS 6.4 operating system is complete, there will be a my.cnf in the/etc directory.
This file needs to be renamed to another name, such as:/etc/my.cnf.bak, otherwise,
The file will interfere with the correct configuration of the source installation of MySQL, causing the failure to start.
After updating the system with Yum Update, you will need to check if there is an extra my.cnf in the/etc directory.
If more, rename it to something else. Otherwise, MySQL will start with this configuration file, which may cause problems such as an inability to start properly.
Start MySQL
Add services, Copy service scripts to the INIT.D directory, and set boot boot
CP support-files/mysql.server/etc/init.d/mysqlchkconfig MySQL onservice mysql start--start MySQL
Configure users
After MySQL starts successfully, Root does not have a password, we need to set the root password.
Before setting, we need to set path, or we can't call MySQL directly
Modify the/etc/profile file to add at the end of the file
Path=/usr/local/mysql/bin: $PATHexport PATH
Close the file, run the following command, and let the configuration take effect immediately
Source/etc/profile
Now, we can enter MySQL in the terminal directly into the MySQL environment
Execute the following command to modify the root password
Mysql-uroot mysql> SET PASSWORD = PASSWORD (' 123456 ');
Note: If-bash:mysql:command not found appears
Cause: This is because the system will find the command under/usr/bin by default, if this command is not in this directory,
Of course the command cannot be found, all we need to do is map a link to the/usr/bin directory, which is equivalent to creating a linked file.
First you need to know the full path of the MySQL command or mysqladmin command,
For example, the path to MySQL is:/usr/local/mysql/bin/mysql, we can execute the command:
# ln-s/usr/local/mysql/bin/mysql/usr/bin
To set the root user to have remote access, perform
Mysql> GRANT All privileges on * * to ' root ' @ ' 172.16.% ' identified by 'password' with GRANT OPTION;
GRANT select,update,delete, insert on jobs.* to ' java @ '% ';
Bold password for remote access, the root user's password can be different from the local.
Configuring firewalls
Firewall 3306 port is not enabled by default, to remote access, you need to open this port
Open/etc/sysconfig/iptables
Under "-A input–m State--state new–m tcp–p–dport 22–j ACCEPT", add:
-A input-m state--state new-m tcp-p-dport 3306-j ACCEPT
Then save and close the file, run the following command in the terminal and refresh the firewall configuration:
Service Iptables Restart
OK, all configured, you can access your MySQL
To add a user and authorize:
Grant all privileges the jobs.* to ' Java ' @ ' percent ' identified by ' [email protected] ' with GRANT OPTION;
FIREWALLD is used as a firewall by default in CentOS 7, so after modifying iptables, it doesn't work after rebooting the system.
The Add port method in Firewalld is as follows:
Firewall-cmd--zone=public--add-port=3306/tcp--permanent
Firewall-cmd--reload
Linux operating system-source package installation MySQL