CentOS安装MySQL8.0.11
总的思路就是:安装MySQL,编写配置文件,配置环境变量,成功开启服务,登陆并修改ROOT密码
开启远程访问的思路就是:授权用户所有IP都可以访问,系统的数据库端口放行
(安装步骤就不详细展开了,网上教程很多,步骤如下)
-
下载解压mysql的压缩包,文件夹改名
mysql
tar -zxvf mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz #解压安装包
mv mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz mysql #修改文件夹名称 -
创建用户和用户组
groupadd mysql #创建组
useradd -g mysql mysql #创建用户 -
创建data文件存放数据,并授权全部文件
mkdir /mysql解压文件夹/data #创建data文件夹,用于存放数据库表
chown -r -g mysql:mysql /mysql解压文件夹 #修改权限 -
初始化数据库,并记录生成的随机密码
bin/mysqld --initialize --user=mysql --basedir=/opt/mysql8.0 --datadir=/opt/mysql8.0/data #初始化MySQL,会生成默认密码,用于第一次登陆
-
创建my.cnf配置文件文件配置MySQL
因为mysql启动会自动寻找/etc/my.cnf配置文件,所以把配置文件放到/etc目录下,命名为my.cnf
[mysqld] #Rove 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 # These are commonly set, remove the # and set as required.
basedir = /opt/mysql
datadir = /opt/mysql/data
socket = /tmp/mysql.sock
log-error = /opt/mysql/data/error.log
pid-file = /opt/mysql/data/mysql.pid
tmpdir = /tmp
port = 3306
#lower_case_table_names = 1
# server_id = .....
# socket = .....
#lower_case_table_names = 1
max_allowed_packet=32M
default-authentication-plugin = mysql_native_password
#lower_case_file_system = on
#lower_case_table_names = 1
log_bin_trust_function_creators = ON
# 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 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES -
设置开机自启动
# cd /mysql解压目录/support-files/
# cp mysql.server /etc/init.d/mysql
# chmod +x /etc/init.d/mysql -
注册服务
chkconfig --add mysql
-
etc/ld.so.conf要配置路径
/mysql安装目录全路径/lib
-
配置环境变量
export PATH=$PATH:/mysql解压全路径/bin:/mysql解压全路径/lib
-
启动MySQL,登陆,输入之前随机生成的密码
service mysql start #启动mysql
mysql -uroot -p #登陆 然后输入之前初始化自动生成的密码登陆 -
修改root密码
alter user 'root'@'localhost' identified by '你的新的root账户密码';
开启MySQL远程访问
-
修改root用户可访问的ip:
host选项由loaclhost变更为%
,意为允许所有ip登陆访问use mysql; #切换到mysql库
update user set host ='%' where user='root'; #修改host为所有IP 修改系统防火墙允许3306端口通过
-
MySQL8.0版本还需要修改密码的加密方式:
先切换到mysql库
use mysql
一.修改加密方式
ALTER USER'root'@'%' IDENTIFIED BY '你的密码' PASSWORD EXPIRE NEVER;
二.修改密码
ALTER USER'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的密码';
三.授权root用户可以远程访问
GRANT ALL ON *.* TO 'root'@'%';
四.刷新
FLUSH PRIVILEGES;
然后重启服务 远程客户端打开sqlyog访问测试