Linux二進制包安裝MySQL 5.7的步驟

原文地址:https://zhangnq.com/3018.htmlhtml

MySQL 5.7提供二進制包的安裝,相比yum安裝麻煩點,但相比編譯安裝仍是會方便不少。二進制包不須要自行編譯mysql源碼,瞎下載後可直接使用,綠色版安裝。二進制包安裝也和編譯同樣,能夠靈活指定須要的MySQL版本。下面就以centos系統爲例安裝。mysql

1、下載MySQL 5.7二進制包

下載頁面:https://dev.mysql.com/downloads/mysql/5.7.html#downloadslinux

OS選擇:linux generic,按照系統版本下載。sql

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

TIM截圖20190511225357

2、建立用戶

groupadd mysql
useradd -g mysql -s /sbin/nologin mysql

3、解壓安裝

tar zxf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.30-linux-glibc2.12-x86_64 /usr/local/mysql

4、設置環境變量

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

5、配置MySQL

例如把mysql數據放在/data/mysql目錄,建立目錄。vim

mkdir -pv /data/mysql
chown mysql.mysql /data/mysql

配置my.cnf,例如centos

vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock

[mysqld]
port = 3306
socket = /tmp/mysql.sock
pid_file = /data/mysql/mysql.pid
datadir = /data/mysql
default_storage_engine = InnoDB
max_allowed_packet = 512M
max_connections = 2048
open_files_limit = 65535

skip-name-resolve
lower_case_table_names=1

character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'

innodb_buffer_pool_size = 512M
innodb_log_file_size = 1024M
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 0

key_buffer_size = 64M

log-error = /data/mysql/mysql_error.log

log-bin = /data/mysql/mysql-bin
binlog_format = mixed
expire_logs_days = 10

slow_query_log = 1
slow_query_log_file = /data/mysql/slow_query.log
long_query_time = 1

server-id=1

具體路徑和配置根據本身需求能夠修改。安全

6、初始化

執行初始化命令,執行完會在 /data/mysql 生成數據文件。socket

mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql

在日誌文件裏會提示一個臨時密碼,記錄這個密碼。本例中是 3igikt:T&p1ride

TIM截圖20190511232138

7、配置啓動腳本

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

更改其中的basedir和datadir
chkconfig --add mysqld
chkconfig  mysqld on
chkconfig --list |grep mysqld

8、啓動MySQL

/etc/init.d/mysqld start

看到進程說明啓動成功。測試

TIM截圖20190511232716

9、登陸和重置root密碼

# mysql -uroot -p
Enter password: 輸入上面的臨時密碼
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.26-log

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> show databases ;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user user() identified by "123456";
Query OK, 0 rows affected (0.43 sec)
mysql> exit
# mysql -uroot -p123456
# 新密碼能夠登陸了

10、安全設置

可根據本身須要設置MySQL的安全配置。密碼複雜度插件測試環境我就不安裝了。例如

# /usr/local/mysql/bin/mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: 
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : 

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

到這裏linux下二進制方式安裝MySQL就完成了。

相關文章
相關標籤/搜索