Tenken blog

Linux安装glibc版mysql-5.7.15

Linux环境下安装MySQL有很多方式,例如:源码编译安装,glibc版的二进制包安装,还有yum方式安装。yum方式安装最为方便,但是版本一般比较老,源码编译安装相对来讲比较麻烦,要想安装好依赖库,缺少一个都可能编译出错,glibc版本相对比较方便,只要指定对应的位置一般都不会出错。本文主要就是讲glibc版本的安装。

准备工作

1、下载好mysql-5.7.15-linux-glibc2.5-i686.tar.gz安装包,下载地址可以是MySQL官网,也可以是国内的镜像地址,如:http://mirrors.sohu.com/mysql/,下载最新版即可。
2、将mysql的安装包上传到服务器,路径:/usr/local/

安装MySQL

##进入安装目录

1
cd /usr/local/

##解压安装包

1
tar -xvf mysql-5.7.15-linux-glibc2.5-i686.tar.gz

##将安装包命名为MySQL

1
mv mysql-5.7.15-linux-glibc2.5 mysql

##创建MySQL用户组

1
groupadd mysql

##创建MySQL用户

1
useradd -g mysql mysql -s /bin/false

##创建MySQL的data目录(这个可以自定义)

1
mkdir -p /opt/mysql/data

##改变目录的所有者

1
chown -R mysql:mysql /opt/mysql/

##进入MySQL目录开始安装

1
2
cd mysql
./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/opt/mysql/data --initialize

##会出现下面提示,记住root账号的初始密码:i<VzkKS)P9dH,修改密码是要用到
2016-10-2T02:18:23.437852Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-10-2T02:18:23.718104Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-10-2T02:18:23.866501Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this
server has been started. Generating a new UUID: 9731b834-3cd6-11e6-8654-fcaa14e34b30.
2016-10-2T02:18:23.896540Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened.
2016-10-2T02:18:23.898416Z 1 [Note] A temporary password is generated for root@localhost: i<VzkKS)P9dH

##到了这里已经成功了一半

##为了避免启动出错,需要修改一下启动文件

1
vi support-files/mysql.server

##找到basedir和datadir,修改为安装目录和指定的data目录

1
2
basedir=/usr/local/mysql
datadir=/opt/mysql/data

##保存退出

##拷贝配置文件到/etc/下

1
cp support-files/my-default.cnf /etc/my.cnf

##编辑my.cnf

1
vi /etc/my.cnf

##添加下面内容

1
2
3
4
5
[mysqld]
basedir=/usr/local/mysql
datadir=/opt/mysql/data
user=mysql
port=3306

##把sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES这一句去掉(避免启动出错)

##保存退出

##拷贝启动文件到/etc/init.d/

1
cp support-files/mysql.server /etc/init.d/mysql

##添加执行权限

1
chmod +x /etc/init.d/mysql

##添加开启启动MySQL

1
2
chkconfig --add mysql
chkconfig mysql on

##启动MySQL测试一下

1
service mysql start

##看到这一句,代表MySQL已经成功启动:Starting MySQL. SUCCESS!

修改MySQL初始密码

##创建一个软连接

1
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

##用初始密码登录MySQL

1
/usr/local/mysql/bin/mysql_secure_installation -p

##出现以下提示
mysql_secure_installation: [Warning] Using a password on the command line interface can be insecure.

Securing the MySQL server deployment.

Enter password for user root: ##输入初始密码

The existing password for the user account root has expired. Please set a new password.

New password: ##输入新密码

Re-enter new password: ##输入新密码

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: y ###是否校验密码插件

There are three levels of password validation policy:

LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

###密码设定有三种,LOW:密码长度大于等于8位;

###MEDIUM:密码长度大于等于8位,并且要有数字,大小写字母和特殊符号;

###STRONG:是MEDIUM基础上加上dictionary file(指定密码验证的文件路径)
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1 ###设定密码策略等级,这里选择1
Using existing password for root.

Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : NO ##暂时不修改root密码
… 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 ###是否关闭root远程登陆功能
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!

###修改完成,测试一下

1
mysql -uroot -p

添加MySQL其他用户

##登录MySQL

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@Tenken mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.15-log MySQL Community Server (GPL)

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

###添加一个test用户并且不指定地址

1
2
mysql> create user 'test'@'%'  identified by 'Aa123456&*';
Query OK, 0 rows affected (0.01 sec)

##授权test用户

1
2
grant all privileges on *.* to 'test'@'%' identified by 'Aa123456&*';
Query OK, 0 rows affected (0.01 sec)

##刷下一下权限表

1
2
mysql>flush privileges;
Query OK, 0 rows affected (0.01 sec)

###现在可以用数据库工具来测试test账号了

末尾

可能会出现的问题:
1、–datadir指定目录不能有其他文件,否则会报错,同时要修改目录的权限,否则写入文件失败,同样会报错。
2、启动文件:support-files/mysql.server的basedir和datadir要修改为安装时的配置参数,否则同样会报错

附上修改后的my.cnf文件,仅供参考

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4
[mysqld]
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /opt/mysql/data
pid-file = /opt/mysql/data/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4
#skip-name-resolve
#skip-networking
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30
log_error = /opt/mysql/log/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /opt/mysql/log/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
#lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
#default-storage-engine = MyISAM
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M

请我吃辣条吧~~