1. 程式人生 > >朝花夕拾:linux CentOS 7 安裝mysql 5.7.13

朝花夕拾:linux CentOS 7 安裝mysql 5.7.13

linux centos 7 安裝mysql 5.7

1.安裝環境:

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)

Mysql版本號:mysql-5.7.13-linux-glibc2.5-x86_64.tar

各項配置路徑:
安裝文件下載目錄:/data/software (軟件包所在位置)
Mysql目錄安裝位置:/usr/local/mysql
數據庫保存位置:/data/mysql
日誌保存位置:/data/log/mysql

2.本人百度雲盤分享,下載mysql
https://pan.baidu.com/s/1nuEypO9

3.安裝主要步驟:

# rpm -qa |grep -i mariadb
# rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64

執行如下命名:

# mkdir -p /data/software
# mkdir -p /data/log/mysql 
# cd /data/software    #(上傳安裝包)

通過xftp或 rz命令 上傳mysql安裝包。

# cd /usr/local
# tar -xvf /data/software/mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz  
# mv mysql-5.7.13-linux-glibc2.5-x86_64 mysql          
# echo $?
0
# ll -h
總用量 0
drwxr-xr-x. 2 root root    6 11月  5 2016 bin
drwxr-xr-x. 2 root root    6 11月  5 2016 etc
drwxr-xr-x. 2 root root    6 11月  5 2016 games
drwxr-xr-x. 2 root root    6 11月  5 2016 include
drwxr-xr-x. 2 root root    6 11月  5 2016 lib
drwxr-xr-x. 2 root root    6 11月  5 2016 lib64
drwxr-xr-x. 2 root root    6 11月  5 2016 libexec
drwxr-xr-x. 9 7161 wheel 129 5月  25 2016 mysql-5.7.13-linux-glibc2.5-x86_64
drwxr-xr-x. 2 root root    6 11月  5 2016 sbin
drwxr-xr-x. 5 root root   49 8月  23 00:39 share
drwxr-xr-x. 2 root root    6 11月  5 2016 src
# mkdir -p /data/mysql      #創建數據倉庫目錄
# groupadd mysql    ---新建一個msyql組 
# useradd -r -s    ---新建msyql用戶,禁止登錄shell 
# cd /usr/local/mysql 
# chown -R mysql . 
# chgrp -R mysql .
# chown -R mysql /data/mysql
# cd /usr/local/mysql 
# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql #初始化mysql,記住初始mysql密碼
# Touch mysql.error  
# bin/mysql_ssl_rsa_setup  --datadir=/data/mysql
# cd support-files/
# cp my-default.cnf /etc/my.cnf 
# cp mysql.server /etc/init.d/mysql
# vi /etc/init.d/mysql

將空白的basedir和datadir修改為以下配置:

basedir=/usr/local/mysql
datadir=/data/mysql

# vi /etc/my.cnf
修改為以下內容:

[client]
port = 3306
socket = /opt/mysql/mysql.sock
#character_set_server=utf8
default-character-set=utf8
[mysql]
no-auto-rehash
[mysqld]
#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER
sql_mode=''
#default-character-set=utf8
socket = /opt/mysql/mysql.sock
basedir = /opt/mysql
max_allowed_packet = 32M
datadir = /data/mysql
explicit_defaults_for_timestamp = true
skip-ssl
secure-file-priv = NULL
lower_case_table_names = 1
back_log = 300
max_connections = 3000
max_connect_errors = 100
table_open_cache = 4096
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 128M
join_buffer_size = 128M
explicit_defaults_for_timestamp = true
thread_cache_size = 100
query_cache_size = 256M
query_cache_limit = 4M
ft_min_word_len = 8
thread_stack = 512k
transaction_isolation = REPEATABLE-READ
tmp_table_size = 128M
max_heap_table_size = 128M
#slow_query_log
slow_query_log_file = /data/log/mysql/slow.log
character-set-server=utf8
server_id =1
log-bin=mysqlbin-log
long_query_time = 3
slow_query_log = on
innodb_buffer_pool_size = 1287M                       
innodb_flush_log_at_trx_commit = 2                    
innodb_log_buffer_size = 32M                             
innodb_log_file_size = 512M  
innodb_log_files_in_group = 2 
innodb_max_dirty_pages_pct = 50 
innodb_file_per_table = 1 
binlog_format = ROW  
audit_json_file=on    #保證mysql重啟後自動啟動插件
plugin-load=AUDIT=libaudit_plugin.so    #防止刪除了插件,重啟後又會加載
audit_record_cmds='delete,update,create,drop,alter,grant,truncate'   #要記錄哪些命令語句,因為默認記錄所有操作; 
[mysqldump]
quick
max_allowed_packet = 32M
[mysqld_safe]
open-files-limit = 8192
log-error = /data/log/mysql/mysql_3306.err


以上為my.cnf中的內容

# cd /usr/local/mysql
# mkdir data
# chown -R mysql .
# chgrp -R mysql .
# bin/mysqld_safe --user=mysql &         (執行後,ps –ef|grep mysql,可以看到mysql的進程)
# bin/mysqld_safe  --skip-grant-tables --user=mysql &  (後臺啟動mysql,且忘記mysql密碼時使用)
# bin/mysql --user=root -p

--輸入第6步生成的臨時密碼

修改mysqlroot用戶密碼:

Mysql>set password for 'root'@'localhost' =password('redhat'); 
mysql>update mysql.user set authentication_string=password('redhat') where user='root';
mysql>grant all privileges on *.* to root@'%' identified by 'redhat'; mysql> flush privileges;
mysql> use mysql; mysql> select host,user from mysql.user;
 # vi /etc/profile # 添加mysql系統路徑

添加:
export PATH=/usr/local/mysql/bin:$PATH

# source /etc/profile              #導入配置
# chmod 755 /etc/init.d/mysql   # 配置mysql自動啟動 
# chkconfig --add mysql      #配置mysql自動啟動 
# chkconfig --level 345 mysql on   #配置mysql自動啟動

登錄mysql:

# bin/mysql --user=root -p

至此mysql安裝完成。

總結:

這種方式安裝的mysql,

# systemctl stauts/start/stop mysql.service


等操作不起作用。


#service mysql status/stop

可以運行;

但是service mysql start 不能啟動,需要用:# bin/mysqld_safe --user=mysql & 才能啟動


朝花夕拾:linux CentOS 7 安裝mysql 5.7.13