This article describes in detail in the CentOS Install MySQL under 6.4
5.6.22 process, for the needs of friends to learn reference.
Download the MySQL installation package
1)http://dev.mysql.com/downloads/mysql/ Open the website: Select
Platform: Select Linux-Generic
Select Linux-Generic (glibc 2.5) (x86, 64-bit), RPM for download;
wget http://cdn.mysql.com/Downloads/MySQL-5.6/MySQL-5.6.22-1.linux_glibc2.5.x86_64.rpm-bundle.tar
2) After downloading, decompress and place it in the installation folder:
tar -xf MySQL-5.6.22-1.linux_glibc2.5.x86_64.rpm-bundle.tar mv MySQL-5.6.22-1.linux_glibc2.5.x86_64.rpm-bundle /usr/local/software/ mv MySQL-5.6.22-1.linux_glibc2.5.x86_64.rpm-bundle mysql
Among them, the two are to be used:
MySQL database: MySQL-server-5.6.22-1.linux_glibc2.5.x86_64.rpm
MySQL client: MySQL-client-5.6.22-1.linux_glibc2.5.x86_64.rpm
3) Installation environment:
cat /etc/RedHat-release
CentOS release 6.4 (Final)
II. MySql Installation
1) 3) Inspection of Installation
Before installing MySQL, check whether a MySQL has been installed in the CentOS system. If it has been installed and uninstalled first, it will fail to install the new MySQL.
Rpm-qa | grep MySQL -- Check whether MySQL was installed before the system.
mysql-libs-5.1.47-4.el6.i686 shows that the CentOS 6.0 system comes with a MySQL. We need to delete the old version and execute the following statement with root user.
su -
Password:
rpm -e --nodeps mysql-libs-5.1.47-4.el6.i686
First switch to the "root" user, then execute the deletion statement, after deletion, we look again, found that the old MySQL version of CentOS 6.0 has been successfully deleted.
After deleting the rpm of MySQL, there are also some tail-sweeping operations. There are two kinds of operations on the Internet. (Note: I didn't use either of them here and found that there was no other residual MySQL information in the system.)
The first kind of post-processing: use the following commands for processing.
rm -rf /var/lib/mysql* rm -rf /usr/share/mysql*
Another kind of post-processing: after uninstalling / var/lib/mysql, / etc/my.cnf will be renamed my.cnf.rpmsave, / var/log/mysqld.log will be renamed / var/log/mysqld.log.rpmsave, and if it is determined that it is not used, it will be deleted manually.
2) Install MySql Server
rpm -ivh MySQL-server-5.6.22-1.linux_glibc2.5.x86_64.rpm
Preparing... ########################################### [100%] 1:MySQL-server ########################################### [100%] warning: user mysql does not exist - using root warning: group mysql does not exist - using root 2014-08-10 22:43:44 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2014-08-10 22:43:44 23012 [Note] InnoDB: Using atomics to ref count buffer pool pages 2014-08-10 22:43:44 23012 [Note] InnoDB: The InnoDB memory heap is disabled 2014-08-10 22:43:44 23012 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2014-08-10 22:43:44 23012 [Note] InnoDB: Memory barrier is not used 2014-08-10 22:43:44 23012 [Note] InnoDB: Compressed tables use zlib 1.2.3 2014-08-10 22:43:44 23012 [Note] InnoDB: Using Linux native AIO 2014-08-10 22:43:44 23012 [Note] InnoDB: Not using CPU crc32 instructions 2014-08-10 22:43:44 23012 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2014-08-10 22:43:44 23012 [Note] InnoDB: Completed initialization of buffer pool 2014-08-10 22:43:45 23012 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created! 2014-08-10 22:43:45 23012 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB 2014-08-10 22:43:45 23012 [Note] InnoDB: Database physically writes the file full: wait... 2014-08-10 22:43:45 23012 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB 2014-08-10 22:43:46 23012 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB 2014-08-10 22:43:46 23012 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0 2014-08-10 22:43:46 23012 [Warning] InnoDB: New log files created, LSN=45781 2014-08-10 22:43:46 23012 [Note] InnoDB: Doublewrite buffer not found: creating new 2014-08-10 22:43:46 23012 [Note] InnoDB: Doublewrite buffer created 2014-08-10 22:43:46 23012 [Note] InnoDB: 128 rollback segment(s) are active. 2014-08-10 22:43:46 23012 [Warning] InnoDB: Creating foreign key constraint system tables. 2014-08-10 22:43:47 23012 [Note] InnoDB: Foreign key constraint system tables created 2014-08-10 22:43:47 23012 [Note] InnoDB: Creating tablespace and datafile system tables. 2014-08-10 22:43:47 23012 [Note] InnoDB: Tablespace and datafile system tables created. 2014-08-10 22:43:47 23012 [Note] InnoDB: Waiting for purge to start 2014-08-10 22:43:47 23012 [Note] InnoDB: 5.6.22 started; log sequence number 0 A random root password has been set. You will find it in '/root/.mysql_secret'. 2014-08-10 22:43:48 23012 [Note] Binlog end 2014-08-10 22:43:48 23012 [Note] InnoDB: FTS optimize thread exiting. 2014-08-10 22:43:48 23012 [Note] InnoDB: Starting shutdown... 2014-08-10 22:43:50 23012 [Note] InnoDB: Shutdown completed; log sequence number 1625977 2014-08-10 22:43:50 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2014-08-10 22:43:50 23039 [Note] InnoDB: Using atomics to ref count buffer pool pages 2014-08-10 22:43:50 23039 [Note] InnoDB: The InnoDB memory heap is disabled 2014-08-10 22:43:50 23039 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2014-08-10 22:43:50 23039 [Note] InnoDB: Memory barrier is not used 2014-08-10 22:43:50 23039 [Note] InnoDB: Compressed tables use zlib 1.2.3 2014-08-10 22:43:50 23039 [Note] InnoDB: Using Linux native AIO 2014-08-10 22:43:50 23039 [Note] InnoDB: Not using CPU crc32 instructions 2014-08-10 22:43:50 23039 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2014-08-10 22:43:50 23039 [Note] InnoDB: Completed initialization of buffer pool 2014-08-10 22:43:50 23039 [Note] InnoDB: Highest supported file format is Barracuda. 2014-08-10 22:43:50 23039 [Note] InnoDB: 128 rollback segment(s) are active. 2014-08-10 22:43:50 23039 [Note] InnoDB: Waiting for purge to start 2014-08-10 22:43:50 23039 [Note] InnoDB: 5.6.22 started; log sequence number 1625977 2014-08-10 22:43:50 23039 [Note] Binlog end 2014-08-10 22:43:50 23039 [Note] InnoDB: FTS optimize thread exiting. 2014-08-10 22:43:50 23039 [Note] InnoDB: Starting shutdown... 2014-08-10 22:43:52 23039 [Note] InnoDB: Shutdown completed; log sequence number 1625987 A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER ! You will find that password in '/root/.mysql_secret'. You must change that password on your first connect, no other statement but 'SET PASSWORD' will be accepted. See the manual for the semantics of the 'password expired' flag. Also, the account for the anonymous user has been removed. In addition, you can run: /usr/bin/mysql_secure_installation which will also give you the option of removing the test database. This is strongly recommended for production servers. See the manual for more instructions. Please report any problems at http://bugs.mysql.com/ The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com New default config file was created as /usr/my.cnf and will be used by default by the server when you start it. You may edit this file to change server settings
3) Check whether MySQL 3306 port is open safely. Test whether it is successful to run netstat to see if MySQL port is open, such as opening indicates that the service has started and the installation is successful. The default port for MySQL is 3306.
[root@hadoop Mysql]# netstat -nat
Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:50070 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:50010 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:50075 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:50020 0.0.0.0:* LISTEN tcp 0 0 192.168.128.129:9000 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:50090 0.0.0.0:* LISTEN tcp 1 0 192.168.128.129:35744 63.130.76.64:80 CLOSE_WAIT tcp 0 0 192.168.128.129:34847 192.168.128.129:9000 ESTABLISHED tcp 0 0 192.168.128.129:35770 192.168.128.129:9000 TIME_WAIT tcp 0 52 192.168.128.129:22 192.168.128.1:1297 ESTABLISHED tcp 0 0 192.168.128.129:50968 61.135.185.247:80 ESTABLISHED tcp 0 0 192.168.128.129:9000 192.168.128.129:34847 ESTABLISHED tcp 0 0 :::34803 :::* LISTEN tcp 0 0 :::22 :::* LISTEN tcp 0 0 ::1:631 :::* LISTEN tcp 0 0 :::8088 :::* LISTEN tcp 0 0 :::13562 :::* LISTEN tcp 0 0 :::8030 :::* LISTEN tcp 0 0 :::8031 :::* LISTEN tcp 0 0 :::8032 :::* LISTEN tcp 0 0 :::8033 :::* LISTEN tcp 0 0 :::8040 :::* LISTEN tcp 0 0 :::8042 :::* LISTEN tcp 0 0 ::ffff:192.168.128.129:8031 ::ffff:192.168.128.12:58051 ESTABLISHED tcp 0 0 ::ffff:192.168.128.12:58051 ::ffff:192.168.128.129:8031 ESTABLISHED
4) Start MySql service
[root@hadoop Mysql]# service mysql start Starting MySQL.......... SUCCESS!
5) Installation of Client
[root@hadoop Mysql]# rpm -ivh MySQL-client-5.6.22-1.linux_glibc2.5.x86_64.rpm Preparing... ########################################### [100%] 1:MySQL-client ^C########################################### [100%] Installation completed
Several important directories of MySQL.
After the installation of MySQL, unlike the default installation of SQL Server in a directory, its database files, configuration files and command files are in different directories. It is very important to understand these directories, especially for the beginners of Linux, because the directory structure of Linux itself is more complex, if you do not know the installation directory of MySQL, you can not start to learn in depth.
a. Database directory / var/lib/mysql/
b. Configuration file / usr/share/mysql (mysql.server command and configuration file)
c, related commands / usr/bin(mysqladmin mysqldump, etc.)
D, startup script/etc/rc.d/init.d/(directory of startup script file mysql)
For example: / etc/rc.d/init.d/mysql start/restart/stop/status
6 (optional) Change the MySQL directory. Because MySQL database directory occupies a large disk, and MySQL default data file storage directory is /"var/lib/mysql", you can also move the data directory to the "mysql_data" directory under the "/" root directory (if you do the test, you do not need to move it).
Stop the MySql service process: service mysql stop
Or mysqladmin-u root-p shutdown
MySQL default user name is "root", where "root" and the highest privileged user of Linux "root" is not a moment, and the default user "root" password is empty, so let's enter the password in the picture above, and click Enter directly.
Move the entire directory of "/var/lib/mysql" to "/mysql_data"
mv /var/lib/mysql /mysql_data
7) Find my.cnf configuration file
If there is no my.cnf configuration file in the "/etc/" directory, please go to "/usr/share/mysql/" and find it.
my-default.cnf file, copy one of the appropriate configuration files to "/etc/" and rename it "my.cnf". The order is as follows:
cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
The default encoding is changed to UTF-8. Use the following command:
vim /etc /my.cnf
[mysqld] #Add the following command #socket = /var/lib/mysql/mysql/mysql.sock #datadir=/mysql_data/mysql #If you want to change the location of your data storage, you need to specify the storage directory here. character-set-server=utf8 lower_case_table_names=1
# (Note that mysql is installed under linux by default: case sensitive, case insensitive; lower_case_table_names = 0.0: case sensitive, 1: case insensitive)
Be careful:
1) The last line, I did not add this setup to the local installation, can also run as usual, plus it depends on you.
2) If you modify the storage location directory of the data, you can execute the following command to modify the MySQL startup script "/ etc/rc.d/init.d/mysql"
Finally, you need to modify the MySQL startup script / etc/rc.d/init.d/mysql and the datadir=/mysql_data/mysql.
vim /etc/rc.d/init.d/mysql
8) Restart MySQL Service
service mysql start
9) Modify login password
MySQL does not have a password by default. It is self-evident that adding passwords after installation is important. Before modification, log in directly
Check whether the MySql port is open:
tcp 0 0 :::3306 :::* LISTEN 5052/mysqld
Enter mysql:
[root@hadoop init.d]#
mysql
The random password of root is located in / root/.mysql_secret.
If MySql is already connected, you can use the following statement:
mysql> use mysql; mysql> UPDATE user SET Password=PASSWORD('root') where USER='root';
Query OK, 4 rows affected (0.04 sec)
Rows matched: 4 Changed: 4 Warnings: 0
Successful revision;
In addition, if the execution script encounters ERROR 1820 (HY000) after login to mysql database: You must SET PASSWORD before executing this statement, you can solve the problem by resetting the password once.
mysql>set password = password('p12#456');
9) Log in to mysql locally using navicat if you encounter“ Mysql
host '192.168.1.1' is not allowed to connect to this mysql server"
1. Modified table method.
Maybe your account is not allowed to log in remotely, but only in localhost. Log in to the installed computer, log in to mysql, and change the "host" item in the "user" table in the "mysql" database from "localhost" to "%"
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
2. Authorization Law.
For example, if you want myuser to connect to mysql server from any host using mypassword.
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
If you want to allow user myuser to connect to mysql server from host with ip 192.168.1.6 and use mypassword as password
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
If you want to allow myuser to connect to the dk database of mysql server from the host with ip 192.168.1.6 and use mypassword as password
GRANT ALL PRIVILEGES ON dk.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;