Centos 8 Install mysql 8

Centos 8 Install mysql 8_第1张图片

安装插件

shell# yum install -y wget curl net-tools vim numactl perl-Time-HiRes git

插件源

shell# yum install -y epel-release

性能监控,tab补全

shell# yum install -y tmux htop iotop iftop bash-completion

刷新全局变量,立即生效

shell# source /etc/profile.d/bash_completion.sh

下载mysql(需要登陆oracle 账户才可以下载

shell# wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.17-1.el8.x86_64.rpm-bundle.tar

创建mysql解压存放目录,解压mysql

shell# mkdir -p /mysql && tar -xvf mysql-8.0.17-1.el8.x86_64.rpm-bundle.tar -C /mysql

安装mysql

shell# yum localinstall -y /mysql/mysql-community-common-8.0.17-1.el8.x86_64.rpm /mysql/mysql-community-libs-8.0.17-1.el8.x86_64.rpm /mysql/mysql-community-server-8.0.17-1.el8.x86_64.rpm /mysql/mysql-community-client-8.0.17-1.el8.x86_64.rpm 

mysql优化

shell# echo -e "\nlog_timestamps = SYSTEM" "\ncharacter_set_server=utf8" "\nlog_bin_trust_function_creators = on" "\nsql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES">> /etc/my.cnf

启动mysql

shell# systemctl start mysqld && systemctl enable mysqld

防火墙设置

shell# firewall-cmd --zone=public --add-port=3306/tcp --permanent &&  firewall-cmd --reload

mysql生成随机密码

shell# grep 'temporary password' /var/log/mysqld.log

初始化密码

shell# mysql -u root -p

重置Mysql 密码以及权限
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Report@123';

mysql远程连接配置

shell# mysql -u root -pReport@123

mysql> GRANT ALL ON *.* TO 'root'@'%';
mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'Report@123';
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'Report@123';

mysql时区设置

#mysql查看当前时间
mysql> select curtime(); 
+-----------+
| curtime() |
+-----------+
| 15:47:51  |
+-----------+
1 row in set (0.00 sec)

#mysql查看当前时区
mysql> show variables like "%time_zone%";
+------------------+--------+
| Variable_name    | Value  |
+------------------+--------+
| system_time_zone | CST    |
| time_zone        | SYSTEM |
+------------------+--------+
2 rows in set (0.00 sec)

#修改当前时区,以系统时间为主,重启服务生效
shell: echo -e "\nlog_timestamps = SYSTEM" >> vim /etc/my.cnf

#或者修改当前时区,以区域时间为主,重启服务生效
shell: echo -e "\ndefault-time_zone = '+8:00'" >> vim /etc/my.cnf

#或者(修改mysql全局时区为北京时间,即所在的东8区)
mysql> set global time_zone = '+8:00'; 

#修改当前会话时区
mysql> set time_zone = '+8:00';  
mysql> flush privileges;

 

你可能感兴趣的:(Mysql,Centos)