侧边栏壁纸
博主头像
故黎

陈雯是小猪

  • 累计撰写 29 篇文章
  • 累计创建 5 个标签
  • 累计收到 7 条评论
标签搜索

CentOS 7 下二进制安装MySQL5.7

故黎
2018-09-29 / 0 评论 / 0 点赞 / 1,017 阅读 / 5,791 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2021-12-30,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

1.详细安装过程

1.1关闭防火墙

systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)

1.2 检查是否安装NySQL,如果安装 卸载之

rpm -qa |grep mysql
yum remove mysql*

1.3 检查是否安装MariaDB,如果安装 卸载之(重要)

rpm -qa |grep mariadb
yum remove mariadb*

1.4 新增用户/组 参数文件

groupadd mysql
useradd -d /home/mysql -g mysql -m mysql
passwd mysql
mysql

vi ~/.bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin:/u01/MySQL5.7/bin

export PATH

[mysql@localhost ~]$ source .bash_profile

1.5 规划目录 赋权限

mkdir -p /u01/MySQL5.7       

mkdir -p /MySQL/my3306/data
mkdir -p /MySQL/my3306/log/iblog
mkdir -p /MySQL/my3306/log/binlog
mkdir -p /MySQL/my3306/run
mkdir -p /MySQL/my3306/tmp

chown -R mysql:mysql /MySQL/my3306
chown -R mysql:mysql /u01/MySQL5.7
##chown -R 755 /MySQL/my3307

1.6 下载mysql安装介质到目标机器

[root@localhost ~] cd /u01/MySQL5.7
[root@localhost MySQL5.7] ll
total 0
[root@localhost MySQL5.7] ll
total 696028
-rw-r--r--. 1 mysql mysql 712729170 May 14 01:42 mysql-5.7.22-el7-x86_64.tar.gz   

1.8 解压

[mysql@localhost  MySQL5.7] tar -xzvf mysql-5.7.22-el7-x86_64.tar.gz  

[mysql@localhost MySQL5.7] mv  /u01/MySQL5.7/mysql-5.7.22-el7-x86_64/* /u01/MySQL5.7/

1.9初始化数据库

[mysql@localhost ~]$ mysqld --initialize --user=mysql --basedir=/u01/MySQL5.7  --datadir=/MySQL/my3306/data  --explicit_defaults_for_timestamp
2018-05-14T05:52:52.741612Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2018-05-14T05:52:52.742026Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2018-05-14T05:52:53.946033Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-05-14T05:52:54.104581Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-05-14T05:52:54.201291Z 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: 0b79b507-573b-11e8-89dd-000c29a1762c.
2018-05-14T05:52:54.203218Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-05-14T05:52:54.210927Z 1 [Note] A temporary password is generated for root@localhost: ;c_tca9sR;s5

注意保存初始化root用户的密码 ;c_tca9sR;s5

1.10编辑参数文件 my.cnf

vi /MySQL/my3306/my.cnf

[mysqld]
#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
basedir=/u01/MySQL5.7                              #介质目录
datadir=/MySQL/my3306/data                         #数据目录
port=3306                                          #端口
pid-file = /MySQL/my3306/data/mysql.pid            #进程id 
user = mysql                                       #启动用户
socket=/MySQL/my3306/run/mysql.sock                #sock文件地址
bind-address = 0.0.0.0                             #绑定ip 这里表示绑定所有ip
server-id = 1                                      #用于复制环境钟标识实例,这个在复制环境里唯一
character-set-server = utf8                        #服务端默认字符集,很重要,错误设置会出现乱码
max_connections = 1000                             #允许客户端并发连接的最大数量
max_connect_errors = 6000                          #如果客户端尝试连接的错误数量超过这个参数设置的值,则服务器不再接受新的客户端连接。
open_files_limit = 65535                           #操作系统允许MySQL服务打开的文件数量。
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 = /MySQL/my3306/data/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /MySQL/my3306/data/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
#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

[client]
port=3306
socket=/MySQL/my3306/run/mysql.sock

[mysql]
socket=/MySQL/my3306/run/mysql.sock

1.11拷贝my.cnf 以及 mysql.server

cp /MySQL/my3306/my.cnf /etc/my.cnf
cp /u01/MySQL5.7/support-files/mysql.server /etc/init.d/mysqld

1.12编辑 /etc/init.d/mysqld

#添加以下两项
basedir=/u01/MySQL5.7
datadir=/MySQL/my3306/data

1.13.启动数据库

[mysql@localhost ~]$ service mysqld start
Starting MySQL.. SUCCESS! 

1.14.连接数据库 更新初始密码

[mysql@localhost ~]$ 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.

mysql> 
mysql> 
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> set PASSWORD=PASSWORD('root');
Query OK, 0 rows affected, 1 warning (0.03 sec)

mysql> flush privileges;

1.15.配置mysql开机启动

[root@localhost ~] chkconfig mysqld on  
[root@localhost ~] chkconfig 

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
0

评论区