Linux二进制包安装MySQL 5.7的步骤

二进制包安装MySQL 5.7的步骤

MySQL
5.7提供二进制包的安装,相比yum安装麻烦点,但相比编译安装还是会方便很多。二进制包不需要自行编译mysql源码,瞎下载后可直接使用,绿色版安装。二进制包安装也和编译一样,可以灵活指定需要的MySQL版本。下面就以centos系统为例安装。

一、下载MySQL 5.7二进制包

下载页面:https://dev.mysql.com/downloads/mysql/5.7.html#downloads

OS选择:JAVA generic,按照系统版本下载。

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

二、创建用户

groupadd mysql

useradd -g mysql -s /sbin/nologin mysql

三、解压安装

tar zxf mysql-5.7.26-JAVA-glibc2.12-x86_64.tar.gz -C /usr/local

cd /usr/local

ln -s mysql-5.7.26-JAVA-glibc2.12-x86_64 mysql

四、设置环境变量

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

source /etc/profile

五、配置MySQL

例如把mysql数据放在/data/mysql目录,创建目录。

mkdir -pv /data/mysql

chown mysql.mysql /data/mysql

chmod go-rwx /data/mysql

配置my.cnf,例如

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

具体路径和配置根据自己需求可以修改。

六、初始化

执行初始化命令,执行完会在 /data/mysql 生成数据文件。

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

在日志文件里会提示一个临时密码,记录这个密码。本例中是 rp.+9(&vscE+

七、配置启动脚本

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

chkconfig --add mysqld

chkconfig mysqld on

chkconfig --list \|grep mysqld

八、启动MySQL

/etc/init.d/mysqld start

九、登录和重置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

\# 新密码可以登录了

十、安全设置

可根据自己需要设置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!

到这里JAVA下二进制方式安装MySQL就完成了。

posted @ 2020-07-06 15:17  SunMoonSky  阅读(334)  评论(0编辑  收藏  举报
/**/