配置YUM源

# 下载mysql源安装包
shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# 安装mysql源
shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm
shell> yum repolist enabled | grep "mysql.*-community.*"
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
!mysql-connectors-community/x86_64 MySQL Connectors Community                 74
!mysql-tools-community/x86_64      MySQL Tools Community                      74
!mysql57-community/x86_64          MySQL 5.7 Community Server                307

安装MySQL

yum -y install gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake bison git openssl openssl-devel
shell> yum install mysql-community-server

启动mysql

systemctl start mysqld
systemctl enable mysqld.service
systemctl enable mysqld.service
systemctl restart mysqld.service
systemctl status mysqld.service

mysql查找报错信息&配置信息

which mysqld
输出:/usr/sbin/mysqld
/usr/sbin/mysqld --verbose --help |grep -A 1 'Default options'
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
lower_case_table_names=1
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
#validate_password = off
[mysqld]
#character_set_server=utf8
#init_connect='SET NAMES utf8'
#skip-grant-tables
wait_timeout=86400

character-set-server=utf8mb4
[mysql]
default-character-set=utf8mb4
修改默认密码
grep 'temporary password' /var/log/mysqld.log

密码不对 or 找不到密码怎嘛办..?

  1. 修改配置文件
    vim /etc/my.cnf
    在[mysqld]节点添加
    skip-grant-tables
  1. 重启mysql
  2. 用空密码进入
    mysql -uroot
      
    update mysql.user set authentication_string=password('123456') where user='root' and Host = 'localhost';
    flush privileges;
    exit;
  1. 还原my.cnf

授权远程连接权限

mysql -u root -p

mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;#重载授权表:
exit;
02-12 07:56