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

在這裏插入圖片描述

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.登錄數據庫並修改密碼

[root@bogon 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.

root@bogon 21:57:  [(none)]> 
root@bogon 21:57:  [(none)]> SET PASSWORD = PASSWORD('root');
#設置遠程連接權限
root@bogon 21:57:  [(none)]>update mysql.user set host = '%' where user ='root';
root@bogon 21:57:  [(none)]> flush privileges;
```

12.重新登錄數據庫

    [root@bogon 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.
    
    root@bogon 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章