CentOS 8.0安装MYSQL8.0.20

  • 创建mysql文件夹
cd /use/loca
mkdir mysql
cd mysql
  • 下载mysql8.0安装包
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

官网地址:https://dev.mysql.com/downloads/mysql/

  • 解压mysql8.0安装包
tar xvJf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz 
  • 重命名解压出来的文件夹,这里改成mysql-8.
mv mysql-8.0.20-linux-glibc2.12-x86_64 mysql-8.0
  • /use/local/mysql文件夹下创建data文件夹 存储文件
mkdir data
  • 分别创建用户组以及用户和密码(如果提示已存在说明之前有创建过了)
groupadd mysql
useradd -g mysql mysql
  • 授权刚刚新建的用户
chown -R mysql.mysql /usr/local/mysql/mysql-8.0
chmod 750 /usr/local/mysql/data -R
  • 配置环境,编辑/etc/profile文件
vim /etc/profile

在最后一行加
export PATH=$PATH:/usr/local/mysql/mysql-8.0/bin:/usr/local/mysql/mysql-8.0/lib

  • 编辑my.cnf文件
vi /etc/my.cnf

按下面复制进去就好了,#号开头的不用管,一样,添加完之后,换行,打出“:sq”,用来保存文件并退出

[mysql]
default-character-set=utf8mb4
[client]
#port=3306
socket=/var/lib/mysql/mysql.sock

[mysqld]
#port=3306
#server-id=3306
user=mysql
general_log = 1
general_log_file= /var/log/mysql/mysql.log
socket=/var/lib/mysql/mysql.sock
basedir=/usr/local/mysql/mysql-8.0
datadir=/usr/local/mysql/data
log-bin=/usr/local/mysql/data/mysql-bin
innodb_data_home_dir=/usr/local/mysql/data
innodb_log_group_home_dir=/usr/local/mysql/data/
character-set-server=utf8mb4
lower_case_table_names=1
autocommit=1
default_authentication_plugin=mysql_native_password
symbolic-links=0
# Disabling symbolic-links is recommended to prevent assorted security risks
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
#分组查询
sql_mode=NO_ENGINE_SUBSTITUTION
#最大执行字符穿
group_concat_max_len=102400
#连接数
max_connections=1000

[mysqld_safe]
log-error=/usr/local/mysql/data/mysql.log
pid-file=/usr/local/mysql/data/mysql.pid

#
# include all files from the config directory
  • 切换到/usr/local/mysql/mysql-8.0/bin目录下
cd bin
  • 初始化基础信息,得到数据库的初始密码(在/usr/local/mysql/mysql-8.0/bin目录下执行)
./mysqld --user=mysql --basedir=/usr/local/mysql/mysql-8.0 --datadir=/usr/local/mysql/data/ --initialize

注意此时要注意日志里面会打印出初始密码。最好保存到本地。

  • 复制 mysql.server 文件,在/usr/local/mysql/mysql-8.0目录下执行
cp -a ./support-files/mysql.server /etc/init.d/mysql 
cp -a ./support-files/mysql.server /etc/init.d/mysqld
  • 赋予权限
chown 777 /etc/my.cnf
chmod +x /etc/init.d/mysql
chmod +x /etc/init.d/mysqld
  • 检查一下/var/lib/mysql是否存在,否则进行创建
mkdir /var/lib/mysql 
  • 然后再赋予权限
chown -R mysql:mysql /var/lib/mysql/ 
  • 启动数据库,有SUCCESS字眼说明MySQL安装完成
service mysql start
  • 登录MySQL
mysql -u root -p

输入初始密码

  • 修改数据库root账号的密码,并设置可以远程访问(因为root默认是不能远程访问的)
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
  • 执行flush privileges; 使密码生效
flush privileges;
  • 选择数据库
 use mysql;
  • 再修改远程连接并生效
update user set host='%' where user='root';
  • 执行提交命令,搞定!
flush privileges;

你可能感兴趣的:(centos,mysql,linux)