Uninstall the old version
See if MySQL Server is installed on the system:
Use the following command to check whether MySQL Server is installed
If it exists, use some commands to uninstallrpm -qa | grep mysql
rpm -e mysql //General deletion mode rpm -e --nodeps mysql // Strong deletion mode, if you use the above command to delete, prompt other files that depend on it, then you can use this command to delete them forcefully.
Install MySQL Server:
Install packages (dependency packages) that compile code, and use yum to install them here.
Download MySQL Server-5.6.21 address: http://download.csdn.net/detail/guishengbin/9842071
yum -y install make gcc-c++ cmake bison-devel ncurses-devel bison perl perl-devel perl perl-devel
tar xvf mysql-5.6.21.tar.gz
cd mysql-5.6.21
Compile and install:
Pre-compile with cmake
cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/usr/local/mysql/data/mysql \ -DSYSCONFDIR=/etc \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DWITH_FEDERATED_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DENABLE_DTRACE=0 \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_EMBEDDED_SERVER=1 \ -DMYSQL_TCP_PORT=3306
Ensure that the directory already exists: / usr/local/mysql/data/mysql
Wait quietly for the process to complete.
Compile and install:
make && make install
To rerun the configuration after an error, you need to delete the CMakeCache.txt file
make clean rm -f CMakeCache.txt
Setting permissions
Use the following command to see if there are mysql users and user groups
If not, createcat /etc/passwd //View User List cat /etc/group //View User Group List
Modify / usr/local/mysql permissionsgroupadd mysql useradd -g mysql mysql
Initialization configurationchown -R mysql:mysql /usr/local/mysql
Enter the installation path
Enter the installation path, execute the initialization configuration script, and create the database and tables that come with the system.cd /usr/local/mysql
Note: When starting MySQL service, I will search my.cnf in a certain order, first in the / etc directory, and if I can't find it, "$basedir/my.cnf", in this case, / usr/local/mysql/my.cnf, which is the default location of the new version of MySQL configuration file!scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/mysql --user=mysql
Note: After the minimum installation of the CentOS 6.4 operating system, there will be a my.cnf in the / etc directory. You need to rename this file to another name, such as: / etc/my.cnf.bak. Otherwise, this file will interfere with the correct configuration of MySQL installed in the source code and cause it to be unable to start.
After using "yum update" to update the system, you need to check whether there will be an additional my.cnf in the / etc directory, and if so, rename it to something else. Otherwise, MySQL will start using this configuration file, which may cause problems such as failure to start properly.
Start MySQL
Add services, copy service scripts to init.d directory, and set boot start
cp support-files/mysql.server /etc/init.d/mysql chkconfig mysql on service mysql start //Start MySQL
Configuring users
After MySQL is started successfully, root has no password by default. We need to set the root password.Before setting up, we need to set up PATH first, otherwise we can not find calling mysql command directly.
Modify the / etc/profile file and add it at the end of the file
Close the file and run the following command to make the configuration take effect immediatelyPATH=/usr/local/mysql/bin:$PATH export PATH
Now, we can enter mysql directly into the terminal, mysql environment.source /etc/profile
Perform the following command to modify the root password
To set up remote access for root users, execute the following commands to authorizemysql -uroot mysql> SET PASSWORD = PASSWORD('123456');
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
Configuring firewalls
Port 3306 of the firewall is not opened by default. To access it remotely, you need to open this port.Open / etc/sysconfig/iptables
Under "- A INPUT M state state NEW MTCP p dport 22 j ACCEPT", add:
Then save and close the file, run the following commands in the terminal, and refresh the firewall configuration-A INPUT -m state --state NEW -m tcp -p -dport 3306 -j ACCEPT
Restart mysql service, all configuration is completed, you can use it.