I. On-line installation
Yum List | grep MySQL
Displays the version information for MySQL on the Yum server
Install with the following command:
Yum install-y mysql-server MySQL mysql-devel
After the installation is complete, view the installed version number by following the command
Rpm-qi Mysql-server
Server-related configuration
Service mysqld Start #开启服务器
Service mysqld Restart #重启服务器
Service mysqld Stop #关闭服务器
Chkconfig--list | grep mysqld #查看mysqld是否开机启动
Chkconfig mysqld on #设置开机启动mysql
Mysqladmin-u root password ' root ' # The root account is set to root by this command
Mysql-u root-p #登陆数据库
/etc/my.cnf This is the main configuration file for MySQL
/var/lib/mysql Database file storage location for MySQL database
Ii. source code compilation and installation
1. Download and install the library required to compile MySQL source code
sudo apt-get install build-essential libncurses5-dev cmake
2. Adding MySQL user groups and users
Groupadd MySQL
useradd-g MySQL MySQL
3. Create MySQL Software installation directory and data storage directory
Mkdir-p/opt/mysql #MySQL安装目录
Chown-r Mysql:mysql/opt/mysql
Mkdir-p/data/mysql #MySQL数据存放目录
Mkdir-p/data/mysql/data #存放数据
Mkdir-p/data/mysql/log #存放日志
Mkdir-p/data/mysql/tmp #存放临时文件
Chown-r Mysql:mysql/data/mysql
4. CMake Compile and install MySQL
TAR-ZXVF mysql-5.6.13.tar.gz
CD mysql-5.6.13
CMake. -dcmake_install_prefix=/opt/mysql-dmysql_datadir=/data/mysql-dsysconfdir=/opt/mysql-ddefault_charset=utf8- Ddefault_collation=utf8_general_ci-dextra_charsets=all-denabled_local_infile=1
Make
Make install
Parameter description:
-dcmake_install_prefix=/opt/mysql//Specify installation directory
-dinstall_datadir=/data/mysql//Specify Data storage directory
-dsysconfdir=/opt/mysql//Specify the profile directory (this example has a configuration file of/opt/mysql/my.cnf)
-ddefault_charset=utf8//Specify character Set
-DDEFAULT_COLLATION=UTF8_GENERAL_CI//Specify check character
-dextra_charsets=all//Install all extended character sets
-denabled_local_infile=1//Allow import of data from local
After successful execution of the above steps, the MySQL software has been successfully installed into the/opt/mysql directory.
5. Edit the configuration file my.cnf
[Client]
Port= 3306
Socket =/opt/mysql/run/mysql.sock
[MySQL]
[Mysqld_safe]
Pid-file =/opt/mysql/run/mysqld.pid
Socket =/opt/mysql/run/mysql.sock
Nice= 0
[Mysqld]
# # # # Baes Dir # #
Basedir =/opt/mysql
DataDir =/data/mysql/data
Tmpdir =/data/mysql/tmp
Socket =/opt/mysql/run/mysql.sock
User=mysql
# # # Base Configure Info # # # #
Port = 3306
Skip-external-locking
#
# Instead of skip-networking The default is now-listen only on
# localhost which are more compatible and are not less secure.
#bind-address= 127.0.0.1
#
# * Fine Tuning
#
Key_buffer= 16M
max_allowed_packet= 16M
thread_stack= 192K
Thread_cache_size = 8
# This replaces the startup script and checks MyISAM tables if needed
# The first time they is touched
Myisam-recover = BACKUP
#max_connections = 100
#table_cache = 64
#thread_concurrency = 10
#
# * Query Cache Configuration
#
query_cache_limit= 1M
Query_cache_size = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware the this-log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file =/var/log/mysql/mysql.log
#general_log = 1
Log-error =/data/mysql/log/alert.log
Slow_query_log_file=/data/mysql/log/slow.log
# Here's can see queries with especially long duration
#log_slow_queries =/var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
# # # Binary log && Relay Log # # # #
#binlog_format = ' MIXED '
Log-bin =/data/mysql/log/mysql-bin
Log-slave-updates = 1
Relay-log =/data/mysql/log/mysqld-relay-bin
Relay-log-index =/data/mysql/log/mysqld-relay-bin.index
Master-info-file =/data/mysql/log/master.info
Relay-log-info-file =/data/mysql/log/relay-log.info
Max_binlog_size = 100M
[Mysqldump]
Quick
Quote-names
max_allowed_packet= 16M
[MySQL]
#no-auto-rehash# faster start of MySQL but no tab completition
[Isamchk]
Key_buffer= 16M
6. Create a database
/opt/mysql/scripts/mysql_install_db--user=mysql--explicit_defaults_for_timestamp--basedir=/opt/mysql/
The above building statement will generate the corresponding data file and log file according to the data file directory and log file directory set in My.cnf, and create the system database (such as Mysql,test,information_schema,performance_schema).
7. Start MySQL
/opt/mysql/support-files/mysql.server start
After successful startup, you can log in as root (the default root user does not have a password)
/opt/mysql/bin/mysql-u Root
See if you can sign in
8. Set Root password
mysqladmin-u root password ' 123456a? '
Mysql-uroot-p
GRANT all privileges on * * to ' root ' @ '% ' identified by ' 123456a? ' With GRANT OPTION;
9. Finally, add MySQL to the system startup and boot
In the/etc/profile file, add
Export path= $PATH:/opt/mysql/bin
CP./SUPPORT-FILES/MYSQL.SERVER/ETC/INIT.D/MYSQLD #把Mysql加入系统启动
chmod 755/etc/init.d/mysqld #增加执行权限
Update-rc.d-f mysqld Defaults #加入开机启动