linux下安装mysql二进制版本(5.7.11)

版本:社区版 5.7.11


我这里下载的是mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
1.创建mysql用户和用户组
#groupadd mysql
#useradd -g mysql mysql
#passwd mysql


2.下载解压二进制文件,解压,进入解压出来的文件
[root@host01 db]# tar -xvf mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
[root@host01 db]# mv mysql-5.7.11-linux-glibc2.5-x86_64 mysqlmha
[root@host01 mysqlmha]# ls -al
total 60
drwxr-xr-x  9 7161 wheel  4096 Feb  2 08:17 .
drwxr-xr-x  4 root root   4096 Apr 11 13:16 ..
drwxr-xr-x  2 7161 wheel  4096 Feb  2 08:17 bin
-rw-r--r--  1 7161 wheel 17987 Feb  2 07:31 COPYING
drwxr-xr-x  2 7161 wheel  4096 Feb  2 08:17 docs
drwxr-xr-x  3 7161 wheel  4096 Feb  2 08:17 include
drwxr-xr-x  5 7161 wheel  4096 Feb  2 08:17 lib
drwxr-xr-x  4 7161 wheel  4096 Feb  2 08:17 man
-rw-r--r--  1 7161 wheel  2478 Feb  2 07:31 README
drwxr-xr-x 28 7161 wheel  4096 Feb  2 08:17 share
drwxr-xr-x  2 7161 wheel  4096 Feb  2 08:17 support-files


3.在mysqlmha下建立data和conf目录
data目录存放数据文件,conf目录存放配置文件
[mysql@host01 mysqlmha]$ cd /db/mysqlmha
[mysql@host01 mysqlmha]$ mkdir data                        ##数据文件目录
[mysql@host01 mysqlmha]$ mkdir conf                        ## 配置文件目录
[mysql@host01 mysqlmha]$ mkdir redolog                    ##redo日志文件
[mysql@host01 mysqlmha]$ mkdir ibdata                      ##ibdata文件
[mysql@host01 mysqlmha]$ mkdir -p mysqllog/relaylog  ##主从环境relaylog
[mysql@host01 mysqlmha]$ mkdir -p mysqllog/logfile    ##错误日志文件
[mysql@host01 mysqlmha]$ mkdir -p mysqllog/binlog    ##binlog文件

4.在conf目录下创建配置文件my.cnf,配置文件内容如下

[mysqld]
port=3306
basedir=/db/mysqlmha
datadir=/db/mysqlmha/data
character-set-server=utf8
max_connections = 1500
show_compatibility_56=on

sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'

##关闭ssl,默认是开启的
skip_ssl

 


[client]
port = 3306
socket=/db/mysqlmha/mysql.sock
default-character-set = utf8

[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M

5.更改文件夹mysqlmha的文件所属用户
[root@host01 db]# chown -R mysql:mysql mysqlmha


6.创建软连接
[root@host01 db]# mkdir -p /usr/local/mysql/bin
[root@host01 db]# ln -s /db/mysqlmha/bin/mysqld /usr/local/mysql/bin/mysqld


 

6.修改系统配置

vi /etc/security/limits.conf ,最后面增加两行
* hard nofile 65535
* soft nofile 65535


##生效应用
#sysctl -p
然后退出重新登录

 

 

7.初始化数据库

root账户下
root@host02 bin]# ./mysqld --initialize --user=mysql --basedir=/db/mysqlmha --datadir=/db/mysqlmha/data --lc_messages_dir=/db/mysqlmha/share --lc_messages=en_US
2016-12-09T20:36:23.865898Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-12-09T20:36:27.979029Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-12-09T20:36:28.110580Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-12-09T20:36:28.134481Z 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: 2906324e-be4f-11e6-bc0a-080027705c2d.
2016-12-09T20:36:28.135350Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-12-09T20:36:28.136299Z 1 [Note] A temporary password is generated for root@localhost: kVQ2Nnsd:7oE
  我在另外一台机器执行如上命令的时候,系统没有任何的反应,后来发现之前安装过mariadb,etc目录下有my.cnf该文件,删除该文件再次执行即可。

执行如上命令包如下错误,是因为没有安装libaio包的原因,执行yum install libaio* 安装即可.
./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

 5.6版本采用mysql_install_db安装

#./mysql_install_db --user=mysql --basedir=/db/mysqlmha --datadir=/db/mysqlmha/data

8.安装ssl_rsa
[mysql@host01 bin]$ ./mysql_ssl_rsa_setup --user=mysql --basedir=/db/mysqlmha --datadir=/db/mysqlmha/data


9.启动mysql(在mysql用户下执行)
[mysql@host01 bin]$ ./mysqld_safe --defaults-file=/db/mysqlmha/conf/my.cnf --user=mysql


启动报如下错误,是因为mysql-err.log文件不存,而mysql账号无法创建该文件(opt目录属主是root)
2017-06-17T02:02:56.971570Z mysqld_safe error: log-error set to '/opt/mysql5718/mysqllog/logfile/mysql-err.log', however file don't exists. Create writable for user 'mysql'.

 手工创建该文件,并重新授权:
[root@redis01 opt]# echo>/opt/mysql5718/mysqllog/logfile/mysql-err.log
[root@redis01 opt]# chown -R mysql:mysql ./mysql5718

11.登陆mysql并修改root密码
[mysql@host01 bin]$ ./mysql -h localhost -u root  -p -S /db/mysqlmha/data/mysql.sock
这里会提示输入密码,我们使用初始化临时提供的密码登陆,步骤7最后一句。
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
这里必须要设置密码才能执行命令
mysql> set password=password('mysql');
Query OK, 0 rows affected, 1 warning (0.00 sec

 

已经有账号的情况下修改密码

update mysql.user set authentication_string=password('mysql') where user='root' and Host='localhost';
flush privileges;

 


5.6版本的修改密码方法为:
update mysql.user set password=PASSWORD('mysql') where user='root';
flush privileges;


12.创建登陆用户

grant ALL on *.* to root@'192.168.56.%' identified by 'mysql' WITH GRANT OPTION;


13.开机自启动
把启动的语句添加到 /etc/rc.d/rc.local文件后面.
赋予执行权限:
[root@redis01 etc]# chmod +x /etc/rc.d/rc.local

root@redis01 opt]# more /etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.


touch /var/lock/subsys/local
/opt/mysql5718/bin/mysqld_safe --defaults-file=/opt/mysql5718/conf/my.cnf --user=mysql



后面附加上上线后配置文件的参数:
[mysql@host02 conf]$ more my.cnf
[mysqld]
port=3306
server-id=1
datadir=/db/mysqlmha/data

character_set_server=utf8mb4
collation-server=utf8mb4_general_ci
init_connect='SET collation_connection = utf8mb4_general_ci'
init_connect='SET NAMES utf8mb4'


max_connections = 1500
skip-external-locking
key_buffer_size=64M
max_allowed_packet=32M
myisam_sort_buffer_size=64M
query_cache_size=32M
#read_buffer_size=2M
sort_buffer_size=2M
#table_cache=512
#thread_cache=20
#thread_concurrency=4
interactive_timeout=86400
wait_timeout=86400
innodb_file_per_table=1
#innodb_additional_mem_pool_size=16M
innodb_buffer_pool_size=128M
innodb_data_home_dir=/db/mysqlmha/ibdata
innodb_data_file_path=ibdata1:100M;ibdata2:100M;ibdata3:100M;ibdata4:100M:autoextend
##这两个参数可以不用指定,要是指定的话,系统启动后会生成ibdata1,ibdata2..4,包括重新生成ibdata1,数据库刚安装的时候系统信息表全部是保留在ibdata1里的,这样的话,这些系统表就会提示不存在.
innodb_flush_log_at_trx_commit=1
innodb_lock_wait_timeout=50
innodb_log_buffer_size=16M
innodb_log_file_size=128M
innodb_log_files_in_group=5
innodb_log_group_home_dir=/db/mysqlmha/redolog
innodb_thread_concurrency=8
log_bin_trust_function_creators=1
event_scheduler=1
max_binlog_size=100M
log-bin=/db/mysqlmha/mysqllog/binlog/binlog.bin
slow_query_log=on
slow_query_log_file=/db/mysqlmha/mysqllog/logfile/slow-query.log
long_query_time=1 ##超过1秒就记录

log_queries_not_using_indexes=on ##未使用索引的也记录到慢日志
log-error=/db/mysqlmha/mysqllog/logfile/mysql-err.log
binlog_format=row
expire_logs_days=3
binlog_cache_size=4MB
skip-host-cache
skip-name-resolve
#read-only
skip-slave-start
relay-log-index=/db/mysqlmha/mysqllog/relaylog/slave-relay-bin.index
relay-log=/db/mysqlmha/mysqllog/relaylog/relaylog-binlog
replicate-ignore-db=information_schema,performance_schema
slave_net_timeout=60
log_slave_updates=1
##lower_case_table_names=1
##language=/db/mysqlmha/share/english
early-plugin-load=""
explicit_defaults_for_timestamp=true
gtid_mode=ON ##开启gtid
enforce_gtid_consistency = ON

sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'

tmpdir = /opt/tmpdir

delay_key_write=off

 myisam_recover_options = force,backup

 ##使用dblink功能

 federated


[client]
port = 3306
socket=/db/mysqlmha/mysql.sock
default-character-set = utf8

[mysqldump]
quick
max_allowed_packet = 32M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M

-- The End --

posted @   slnngk  阅读(283)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2019-02-22 rman copy相关
2019-02-22 修改副本集端口(带仲裁节点)
点击右上角即可分享
微信分享提示