1. Preface
There are three ways to install MySQL: RPM installation, binary package installation, source package installation. These 3 various ways each have the characteristic, the main characteristic refer to the following table. In real-world applications, you can optimize based on the host environment you use, choose the best configuration values, and install customizations more flexibly. Visit the MySQL website http://dev.mysql.com/downloads/download the latest stable release of the corresponding MySQL version, this article on the MySQL 5.6.26 binary version of the installation demo.
|
Rpm |
Binary |
Source |
Advantages |
Easy to install, suitable for beginners |
Simple installation, can be installed into any path, flexibility, a server can install multiple MySQL. |
The actual installed operating system can be customized according to the needs of the compilation, the most flexible, the best performance, one server can install multiple MySQL. |
Disadvantages |
1. You need to download the client and server side separately; 2. Installation path is not flexible, the default path can not be modified, a set of servers can only install one MySQL. |
has been compiled, performance is not as good as the source code compiled, can not be flexibly customized compilation parameters. |
The installation process is more complex and the compilation time is long |
File layout |
/usr/bin client programs and scripts /usr/sbin MySQL Server /var/lib/mysql Log files and databases /usr/share/doc/packages Documentation /usr/include/mysql Include files /usr/lib/mysql Library file /usr/share/mysql error messages and character set files /usr/share/sql-bench Benchmark Program |
Bin client program and Mysqlid server Data log files and databases Doc Documentation and Changelog Include include file Lib Library file Scripts mysql_install_db script to install the system database Share/mysql error Message File Sql-bench Benchmark Program |
Bin client programs and scripts Include/mysql Include files Documents in Info Info format Lib/mysql Library file Libexec MySQL Server Share/mysql error Message File Sql-bench Benchmark program and CRASH-ME test Var Database and log files |
2. Preparation before installation
Test environment for this article: CentOS release 6.4 (Linux version 2.6.32-358.el6.x86_64)
1) Set up MySQL users and groups
Create MySQL user groups and users, if not established, after installing MySQL binary package, MySQL startup will cause problems due to Linux file permissions
New MySQL user group:
[SQL]View Plain Copy
- [[email protected] ~]# Groupadd MySQL
New MySQL User:
[SQL]View Plain Copy
- [[email protected] ~]# useradd-r-g MySQL MySQL
2) New MySQL database data file directory
[SQL]View Plain Copy
- [Email protected] ~]# mkdir-p/data/mysqldb
- [Email protected] ~]# chown-r mysql:mysql/data/mysqldb
- [Email protected] ~]# cd/usr/Local
3. Install MySQL
1) Download MySQL binary installation package
: http://dev.mysql.com/downloads/mysql/in Select Platform: Linux-generic, Then download the bottom: mysql-5.6.26-linux-glibc2.5-x86_64..tar.gz (with 64-bit and 32-bit, select as needed)
2) Unpack the binary package
[SQL] view plain copy
- [Email protected] local]# TAR-XZVF mysql-5.6.26.tar.gz
- [[email protected] local]# mv mysql-5.6.26 MySQL
- [Email protected] local]# CD mysql/
- [[email protected] mysql]# chown-r MySQL.
- [[email protected] mysql]# chgrp-r MySQL.
In fact, MySQL has been installed, but also need to initialize, initialize MySQL table, test table, infomation table and so on. DataDir can be other, but it also needs to be chown modified under the creator, otherwise there may be permissions issues.
4. Configure MySQL
[SQL]View Plain Copy
- [Email protected] mysql]# scripts/mysql_install_db.sh --user=mysql--basedir=/usr/local/mysql--datadir=/data/ MySQLdb
[SQL]View Plain Copy
- [Email protected] mysql]# chown-r root.
- [[email protected] mysql]# chown-r mysql data
- [[email protected] mysql]# chgrp-r MySQL.
1) Provide SYSV service script for MySQL
[SQL]View Plain Copy
- [email protected] mysql]# CP support-files/mysql.server/etc/init.d/mysqld
2) Modify the configuration file
[SQL]View Plain Copy
- [email protected] mysql]# CP my.cnf/etc/my.cnf
- [Email protected] mysql]# VI/ETC/MY.CNF
3) Add MySQL to the service list
[SQL]View Plain Copy
- [Email protected] mysql]# chkconfig --add mysqld
- [Email protected] mysql]# chkconfig mysqld on
4) Start the service and use the MySQL user to start the service
[SQL]View Plain Copy
- [Email protected] mysql]# Bin/mysqld_safe --user=mysql
5) Log in to the database
[SQL]View Plain Copy
- [Email protected] mysql]# bin/mysql-u root
6) set root initial password
[SQL]View Plain Copy
- [Email protected] mysql]# bin/mysqladmin-u root password "123456"
7) Other operations
[SQL]View Plain Copy
- mysql> Select user,host,password from MySQL. User --Query MySQL user, password, etc.
- mysql> update MySQL. User set password = password (' 000000 ') where user = ' root ' --Change root password
- mysql> Drop user ' @localhost; --Delete empty users
- Mysql> FLUSH privileges;
Binary package installation MySQL