CentOS7.3安装mysql数据库
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.
修改密码即可解决
上一篇: Vue电商SKU组合算法问题