Linux 安装Mysql 5.7.17手册

2018-08-18 14:593250原创mysql编辑删除

本文链接:https://www.cndba.cn/leo1990/article/2955

2 MySQL 安装

2.1 下载mysql

wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

 

2.2 安装

--创建用户和组:
groupadd mysql
useradd -g mysql mysql
--创建存放数据文件的目录:
--存放日志
mkdir -p /data/mysql/log
chown -R mysql.mysql /data/mysql/log
--存放数据
mkdir -p /data/mysql/data
chown -R mysql.mysql /data/mysql/data
--存放binlog
mkdir -p /data/mysql/binlog/
chown -R mysql.mysql /data/mysql/binlog/
--存放临时文件
mkdir -p /data/mysql/tmp
chown -R mysql.mysql /data/mysql/tmp
--解压缩安装文件,这里将Mariadb安装到/usr/local 目录下:
[root@host1 software]# cd /software/
[root@host1 software]# tar -zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz -C /usr/local
[root@host1 software]# cd /usr/local 
[root@host1 local]# ln -s mysql-5.7.17-linux-glibc2.5-x86_64/ mysql
[root@host1 local]#  ls -ln mysql
lrwxrwxrwx 1 0 0 29 Feb 26 17:00 mysql -> mysql-5.7.17-linux-glibc2.5-x86_64

2.3 配置启动文件

2.3.1 复制/usr/local/mysql/support-files目录下的my-default.cnf 复制给 /etc/my.cnf

[root@host1 mysql]# cd /usr/local/mysql/support-files/
[root@host1 support-files]# pwd
/usr/local/mysql/support-files
[root@host1 support-files]# cp my-default.cnf /etc/my.cnf
注意:如果你在安装时Linux虚拟机时同时安装了默认的mysql,此时操作以上步骤,终端将会提示你文件已存在是否覆盖,输入yes覆盖即可。
[root@host1 support-files]# vi /etc/my.cnf 
在这份文件中可以添加以下配置信息(如果有修改即可)
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set= utf8

[mysql]
no-auto-rehash
default-character-set= utf8

[mysqld]
port = 3306
default-storage-engine=INNODB
basedir = /usr/local/mysql
datadir = /data/mysql/data/
socket = /tmp/mysql.sock
pid-file = /data/mysql/data/mysql.pid
tmpdir = /data/mysql/tmp
character-set-server = utf8
skip_name_resolve = 1
open_files_limit    = 65535
back_log = 1024
max_connections = 1000
max_connect_errors = 1000
slow_query_log = 1
slow_query_log_file = /data/mysql/log/slow.log
log-error = /data/mysql/log/error.log
long_query_time = 0.1
log_queries_not_using_indexes =1
log_throttle_queries_not_using_indexes = 60
server-id = 3306
log-bin = /data/mysql/binlog/mysql-bin
sync_binlog = 1
binlog_cache_size = 4M
max_binlog_cache_size = 2G
max_binlog_size = 1G
expire_logs_days = 7
master_info_repository = TABLE
relay_log_info_repository = TABLE
#gtid_mode = on
#enforce_gtid_consistency = 1
log_slave_updates
binlog_format = row
binlog_checksum = 1
relay_log_recovery = 1
relay-log-purge = 1

#transaction_isolation = REPEATABLE-READ
#innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 1000M
innodb_buffer_pool_instances = 8
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_data_file_path = ibdata1:1G:autoextend
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 32M
innodb_log_file_size = 2G
innodb_log_files_in_group = 2
innodb_max_undo_log_size = 4G

innodb_io_capacity = 4000
innodb_io_capacity_max = 8000
innodb_flush_neighbors = 0
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_purge_threads = 4
innodb_page_cleaners = 4
innodb_open_files = 65535
innodb_max_dirty_pages_pct = 50
innodb_flush_method = O_DIRECT
innodb_file_per_table = 1
innodb_online_alter_log_max_size = 4G

[mysqldump]
quick
max_allowed_packet = 32M

2.3.2 复制/usr/local/mysql/support-files目录下mysql.server 到/etc/init.d/mysql 目录下【目的想实现开机自动执行效果】

执行命令:cp mysql.server /etc/init.d/mysql 
[root@host1 mysql]# cd /usr/local/mysql/support-files
[root@host1 support-files]# pwd
/usr/local/mysql/support-files
[root@host1 support-files]# cp mysql.server /etc/init.d/mysql

2.4 初始化 mysql 的数据库

[root@host1 local]# cd /usr/local/mysql/bin
[root@host1 bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
2017-09-14T09:38:53.271543Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-09-14T09:38:53.271603Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2017-09-14T09:38:53.271610Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2017-09-14T09:38:55.679017Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-09-14T09:38:55.837003Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-09-14T09:38:55.905613Z 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: 86ea10a1-9930-11e7-be22-080027845e3d.
2017-09-14T09:38:55.908909Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-09-14T09:38:55.910660Z 1 [Note] A temporary password is generated for root@localhost: j94fgjDt>g:w(记住这个密码,修改root 密码使用)

2.5 配置mysql环境变量

--编辑文件/etc/profile
vi /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
--环境变量生效
source /etc/profile

2.6 启动 mysql 数据库

[root@dg1 ~]# cd /usr/local/mysql/bin
[root@dg1 bin]# ./mysqld_safe --user=mysql &
--也可以使用service mysql start
[root@host1 tmp]# service mysql start
Starting MySQL.Logging to '/usr/local/mysql/data/host1.err'.
 SUCCESS! 
--也可以用/etc/init.d/mysqld start 命令启动数据库

2.7 修改root密码

[root@host1 tmp]# /usr/local/mysql/bin/mysql -uroot -p
这里使用绝对路径是防止提示密码过期错误,如果服务器没有安装mysql 数据库可使用mysql -uroot -p
ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.
Enter password: (第一次登录输入初始化root密码这里初始化密码 j94fgjDt>g:w)
也可以通过以下命令查询初始化密码
[root@qilin log]# grep 'temporary password'  /data/mysql/log/error.log 
2018-04-27T10:01:54.243279Z 1 [Note] A temporary password is generated for root@localhost: j94fgjDt>g:w

Welcome to the MySQL monitor.  Commands end with ; or /g.
Your MySQL connection id is 3
Server version: 5.7.17

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.

mysql> set password=password('root');
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

2.8 设置开机自启动

[root@host1 bin]# chkconfig --add mysql
[root@host1 bin]# chkconfig mysql on
[root@host1 bin]# chkconfig mysql --list

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]'.

mysql           0:off 1:off 2:on 3:on 4:on 5:on 6:off
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值