mysql-5.7安装

1、下载依赖和数据库安装包

如果缺少:安装libaio库
下载地址:
http://mirror.centos.org/centos/6/os/x86_64/Packages/libaio-0.3.107-10.el6.x86_64.rpm
安装libaio库:
rpm -ivh libaio-0.3.107-10.el6.x86_64.rpm(若在有网情况下可执行yum install libaio)
下载数据库5.7
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz 

2、配置环境

tar xvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.23-linux-glibc2.5-x86_64 /usr/local/mysql

创建启动用户

useradd -s /sbin/nologin -M mysql

创建数据存放路径

cd /data/
mkdir mysql-5.7.23/data -p
mkdir mysql-5.7.23/log
chown -R mysql:mysql mysql-5.7.23

编辑my.cnf

[root@localhost mysql]# cat /etc/my.cnf 
[client]
port = 3308
socket = /tmp/mysql.sock

[mysqld]
server_id=10
port = 3308
user = mysql
character-set-server = utf8mb4
default_storage_engine = innodb
log_timestamps = SYSTEM
socket = /tmp/mysql.sock
basedir = /data/mysql-5.7.23
datadir = /data/mysql-5.7.23/data
pid-file = /data/mysql-5.7.23/data/mysql.pid
max_connections = 1000
max_connect_errors = 1000
table_open_cache = 1024
max_allowed_packet = 128M
open_files_limit = 65535
###====================================[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

#####====================================[log]==============================
log_error = /data/mysql-5.7.23/log/mysql-error.log 
slow_query_log = 1
long_query_time = 1 
slow_query_log_file = /data/mysql-5.7.23/log/mysql-slow.log

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

初始化:

bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql

初始密码可以查看:cat /data/mysql-5.7.23/log/mysql-error.log
没有找到密码的话可以看看这里:cat /root/.mysql_secret

拷贝启动脚本

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

更改mysqld启动参数

vim /etc/init.d/mysqld 
basedir=/data/mysql-5.7.23
datadir=/data/mysql-5.7.23/data

授权

chmod 755 /etc/init.d/mysqld

3、启动、连接(5.7版本的数据库,密码会随机生成,保存在error.log里面)

/etc/init.d/mysqld start
cd /usr/local/mysql
./bin/mysql -uroot -ph*pkEiZTy84/

进去之后先改密码,不然做不了其他操作:

ALTER USER 'root'@'localhost' IDENTIFIED BY  '123456';

如果出现密码策略问题异常信息:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
那我们改下密码策略就可以用简单密码了:

set global validate_password_policy=LOW;
set global validate_password_length=6;
ALTER USER 'root'@'localhost' IDENTIFIED BY  '123456';

你可能感兴趣的:(mysql,数据库)