1. 程式人生 > 實用技巧 >【MySQL Database】install mysql 5.6 on centos

【MySQL Database】install mysql 5.6 on centos

[root@monkey01 ~]# lsb_release -a
LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 6.5 (Final)
Release:        6.5
Codename:       Final

[root@monkey01 ~]# cat >> /etc/hosts <<EOF
192.168.40.34   monkey01
EOF

[root@monkey01 ~]# useradd mysql
[root@monkey01 ~]# id mysql
uid=500(mysql) gid=500(mysql) groups=500(mysql)

[root@monkey01 ~]# cat >> /etc/security/limits.conf <<EOF
mysql            soft    nproc          2048
mysql            hard    nproc          65535
mysql            soft    nofile         2048
mysql            hard    nofile         65535
EOF

[root@monkey01 ~]# yum install -y libaio

[root@monkey01 ~]# rpm -ivh mysql80-community-release-el6-3.noarch.rpm

[root@monkey01 ~]# yum-config-manager --disable mysql80-community

[root@monkey01 ~]# yum-config-manager --enable mysql56-community

[root@monkey01 ~]# yum repolist all | grep mysql

[root@monkey01 ~]# yum install -y mysql-community-server

[root@monkey01 ~]# vim /etc/my.cnf
[mysqld]
port = 3306
user = mysql
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
secure_file_priv = /var/lib/mysql
log-error = mysqld-error.log
character-set-server = utf8mb4
wait_timeout=43200  
interactive_timeout=43200
open-files-limit = 65535
max_allowed_packet = 32M
max_connections = 500
max_connect_errors = 10000
tmp_table_size = 256M
max_heap_table_size = 256M
slow_query_log = 1
long_query_time = 5
slow_query_log_file = mysqld-slow.log
query_cache_type = 0
query_cache_size = 0
key_buffer_size = 32M

innodb_buffer_pool_size = 2G
innodb_buffer_pool_instances = 2
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_log_buffer_size = 16M
innodb_undo_logs= 128
innodb_undo_tablespaces = 3
innodb_large_prefix = 1
innodb_file_format = Barracuda
innodb_file_format_max = Barracuda
innodb_data_file_path = ibdata1:1024M:autoextend

[mysql]
default-character-set = utf8mb4

[client]
default-character-set=utf8mb4

[root@monkey01 ~]# mysql_install_db --user=mysql

[root@monkey01 ~]# service mysqld start
Logging to '/var/lib/mysql/monkey01.err'.
Starting mysqld:                                           [  OK  ]

[root@monkey01 ~]# service mysqld status
mysqld (pid  9172) is running...

[root@monkey01 ~]# netstat -tunlp | grep mysqld
tcp        0      0 :::3306        :::*        LISTEN        9172/mysqld 

[root@monkey01 ~]# mysql_secure_installation

##修改root密碼
Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

##刪除匿名使用者 
Remove anonymous users? [Y/n] y
 ... Success!

 ##禁止root遠端登入
Disallow root login remotely? [Y/n] y
 ... Success!

##刪除測試庫
Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

##重新整理許可權 
Reload privilege tables now? [Y/n] y
 ... Success!

[root@monkey01 ~]# mysql -uroot -p     
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.45 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select version();
+-----------+
| version() |
+-----------+
| 5.6.45    |
+-----------+
1 row in set (0.00 sec)