天天看點

centos MySQL5.7安裝(源碼安裝)

1.下載下傳安裝包

http://mirrors.sohu.com/mysql/MySQL-5.7/

wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
           

2、解壓到/opt下

tar xvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql
           

3.建立使用者

groupadd mysql 
useradd -g mysql  -s  /sbin/nologin -d /usr/local/mysql/  -M mysql
           

4.添加環境變量

echo PATH=$PATH:/usr/local/mysql/bin >>/etc/profile 
source /etc/profile
           

5.建立必要的目錄

mkdir -p /data/mysql/{data,tmp,logs}
           

6.添加配置檔案

vi /etc/my.cnf

####配置檔案内容#####
[client]
#用戶端設定
port    = 3306
socket    = /data/mysql/data/mysql.sock
default-character-set = utf8mb4

[mysqld]
user    = mysql
port    = 3306
socket    = /data/mysql/data/mysql.sock
server-id = 1
pid-file = /data/mysql/data/mysql.pid
#安裝目錄
basedir    = /usr/local/mysql
#資料庫存放目錄
datadir    = /data/mysql/data/
#系統資料庫編碼設定,排序規則
character_set_server = utf8mb4
collation_server = utf8mb4_bin
back_log = 1024
explicit_defaults_for_timestamp = ON
lower_case_table_names = 0
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
max_connections = 512
max_connect_errors = 1000000
table_open_cache = 1024
max_allowed_packet = 8M
thread_stack = 256K
thread_cache_size = 384
skip-external-locking
interactive_timeout = 600
wait_timeout = 3600
log_timestamps = SYSTEM
log-error = /data/mysql/logs/error.log
#預設使用InnoDB存儲引擎
default_storage_engine = InnoDB
innodb_buffer_pool_size = 64M
innodb_purge_threads = 1
innodb_log_buffer_size = 2M
innodb_log_file_size = 128M
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 32M
myisam_sort_buffer_size = 8M
# MySQL重建索引時所允許的最大臨時檔案的大小
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1

[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]

key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M

[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
           

7.添權重限

chown -R mysql:mysql /data/mysql/
chown -R mysql:mysql /usr/local/mysql
           

8.初始化資料庫

yum install -y libaio
 yum -y install numactl
 mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/usr/local/mysql/  --datadir=/data/mysql/data/
           

9.檢視初始密碼

more  /data/mysql/logs/error.log
           
centos MySQL5.7安裝(源碼安裝)

10.啟動資料庫

cp /usr/local/mysql/support-files/mysql.server   /etc/init.d/mysqld
/etc/init.d/mysqld start
Starting MySQL.. SUCCESS!

#設定為開機啟動
chkconfig --level 35 mysqld on
           

11.登入資料庫并修改密碼

[[email protected] support-files]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22-log

Copyright (c) 2000, 2018, 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.

[email protected] 21:57:  [(none)]> 
[email protected] 21:57:  [(none)]> SET PASSWORD = PASSWORD('root');
#設定遠端連接配接權限
[email protected] 21:57:  [(none)]>update mysql.user set host = '%' where user ='root';
[email protected] 21:57:  [(none)]> flush privileges;
```
           

12.重新登入資料庫

[[email protected] support-files]# mysql -uroot -proot                 
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 5
    Server version: 5.7.22-log MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2018, 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.
    
    [email protected] 22:01:  [(none)]> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    4 rows in set (0.00 sec)

如果使用navicat連接配接報2003錯誤 關閉防火牆可以解決


  iptables -F
  service iptables save
  chkconfig iptables off
           

繼續閱讀