mysql-5.7.21 二进制包安装
简介mysql-5.7.21 二进制包安装
二进制包默认安装地址:/usr/local/mysql 所以以下的操作都需要明确这一点,也可以修改,但是在处理其他方面就需要多花时间
mysql5.7.7及以上做了很多改变,5.7.7以前安装方法和以前差不多,初始化也保留了mysql_install_db,5.7.7以后则去掉了该脚本,使用了-initialize或者 --initialize-insecure 参数作为初始化
下面我们完全个性化自定义安装:
一、初始化
1、下载二进制包:mysql-5.7.21-linux-glibc2.12-x86_64.tar
下载地址:https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar
2、将包解压:
tar xv mysql-5.7.21-linux-glibc2.12-x86_64.tar
解压后:
mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
mysql-test-5.7.21-linux-glibc2.12-x86_64.tar.gz
3、解压mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz到指定的目录
tar xf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz -C /apps/
4、修改目录名称
mv mysql-5.7.21-linux-glibc2.12-x86_64 mysql-5.7.21
5、建立软连接
ln -s mysql-5.7.21 mysql
6、添加用户组和用户
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql
7、授权
chown -R mysql.mysql mysql-5.7.21
chown -R mysql.mysql mysql
注意:如果配置多实例的话,安装到本步骤即可,就不用往下进行,如果单实例就继续
8、在/etc目录下创建my.cnf文件,内容如下:(配置文件有待验证)
[client]
port = 3307
socket = /apps/mysql/mysql.sock
[mysqld]
server_id=10
port = 3307
user = mysql
character-set-server = utf8mb4
default_storage_engine = innodb
log_timestamps = SYSTEM
socket = /apps/mysql/mysql.sock
basedir = /apps/mysql
datadir = /apps/mysql/data
pid-file = /apps/mysql/mysql.pid
max_connections = 1000
max_connect_errors = 1000
table_open_cache = 1024
max_allowed_packet = 128M
open_files_limit = 65535
explicit_defaults_for_timestamp=true
#####[innodb]
innodb_buffer_pool_size = 1024M
innodb_file_per_table = 1
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_purge_threads = 2
innodb_flush_log_at_trx_commit = 1
innodb_log_file_size = 512M
innodb_log_files_in_group = 2
innodb_log_buffer_size = 16M
innodb_max_dirty_pages_pct = 80
innodb_lock_wait_timeout = 30
innodb_data_file_path=ibdata1:1024M:autoextend
innodb_undo_tablespaces=3
#####[log]
log_error = /apps/mysql/log/mysql-error.log
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
9、初始化数据库
./bin/mysqld --defaults-file=/apps/mysql/conf/my.cnf --initialize --datadir=/apps/mysql/data/ --basedir=/apps/mysql --user=mysql
执行完后:
2018-04-17T19:34:34.945648Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-04-17T19:34:35.306554Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-04-17T19:34:35.689074Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-04-17T19:34:35.999760Z 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: 5c7be431-4276-11e8-beef-000c295f4e30.
2018-04-17T19:34:36.004881Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-04-17T19:34:36.006748Z 1 [Note] A temporary password is generated for root@localhost:#EnZtrwNq9e3
上面就是默认密码
初始化时候使用的–initialize-insecure参数,不会随机生成密码,登录和原来一样
10、查看帮助信息:
bin/mysqld --verbose --help | more
二、启动mysql实例
1、初始化完成后,就开始准备启动,启动还保持着原来的方式,可以使用mysqld_safe启动,所以参数基本差不多。mysqld_safe启动也是推荐的方式。
./bin/mysqld_safe --defaults-file=/apps/mysql/conf/my.cnf --datadir=/apps/mysql/data/ --basedir=/apps/mysql --user=mysql &
2、本地必须使用socket连接:
bin/mysql -S /apps/mysql/mysql.sock -P3307 -uroot -p
回车输入密码
3、首次进入需要先重置密码,不然操作会提示:
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
4、重置密码:
set password=password('123456');
以上配置就基本完成
错误:
1、mysqld_safe error: log-error set to ‘/apps/mysql/log/mysql-error.log’, however file don’t exists. Create writable for user ‘mysql’.
解决:
echo "" > /apps/mysql/log/mysql-error.log
chown -R mysql.mysql /apps/mysql/log/mysql-error.log