Mysql数据库安装
1.环境
操作系统:CentOS 7.3
软件:MySQL 5.7
下载链接:https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
2.开始安装
2.1.安装依赖包
[root@i-679DDF88 ~]# yum install -y cmake make gcc gcc-c++ libaio ncurses ncurses-devel
2.2 创建mysql用户
[root@i-679DDF88 ~]# groupadd mysql
[root@i-679DDF88 ~]# useradd -g mysql mysql -s /sbin/nologin
2.3 解压复制安装包
[root@i-679DDF88 ~]# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
[root@i-679DDF88 ~]#tar zxf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
[root@i-679DDF88 ~]# mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql
2.4修改目录权限
[root@i-679DDF88 ~]#chown –R mysql:mysql /usr/local/mysql
2.5 初始化数据库
[root@i-679DDF88 ~]# cd /usr/local/mysql/
[root@i-679DDF88 mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
这里会生成一个临时密码
2.6生成key
[root@i-679DDF88 mysql]# bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
2.7 再次修改mysql目录权限
[root@i-679DDF88 local]# chown -R mysql:mysql /usr/local/mysql
2.8 修改配置文件
[root@i-679DDF88 mysql]# vim /etc/my.cnf
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
#不区分大小写
lower_case_table_names = 1
#不开启sql严格模式
sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
log-error=/var/log/mysqld.log
pid-file=/tmp/mysqld.pid
default_password_lifetime=0
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
max_connections = 5000
max_connect_errors = 1000
max_allowed_packet = 128M
innodb_buffer_pool_size = 10240M
innodb_log_file_size = 1024M
lower_case_table_names=1
event_scheduler=ON
skip_name_resolve
back_log=300
user=mysql
server-id=1038003
log-bin=mysql-bin
expire_logs_days = 5
binlog_format = ROW
replicate-wild-ignore-table = information_schema.%
replicate-wild-ignore-table = mysql.%
replicate-wild-ignore-table = performance_schema.%
log_bin_trust_function_creators=1
sync_binlog = 1
innodb_flush_log_at_trx_commit=2
innodb_file_per_table=1
auto_increment_increment=2
auto_increment_offset=2
#密码过期时间,默认为180天,0为永不过期
default_password_lifetime=0
2.9添加系统服务
[root@i-679DDF88 mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@i-679DDF88 mysql]#chkconfig --add mysqld
[root@i-679DDF88 mysql]#chkconfig --level mysqld 12345 on
2.10 创建连接文件
[root@i-679DDF88 mysql]# ln -s /usr/local/mysql/bin/mysql /usr/bin
2.11 启动服务
[root@i-679DDF88 mysql]# /etc/init.d/mysqld start
2.12 连接数据库修改密码
[root@i-679DDF88 mysql]# mysql –uroot -p
alter user user() identified by "newpassword";
3.FAQ
1.查看数据库提示ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
修改密码即可解决