Linux系统安装Mysql8.0流程与遇到的问题

  • Linux系统安装Mysql8.0流程与遇到的问题已关闭评论
  • 13 次浏览
  • A+
所属分类:linux技术
摘要

安装MySQL版本为:8.0.161、首次安装,下载命令:  wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

安装MySQL版本为:8.0.16

1、首次安装,下载命令:

  wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

2、解压 

  tar xvJf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

3.重命名

  mv mysql-8.0.20-linux-glibc2.12-x86_64 mysql-8.0

4.创建用户组、用户及其密码

  groupadd mysql
  useradd -g mysql mysql

6、授权

  chown -R mysql.mysql /usr/local/mysql/mysql-8.0

  chmod 750 /usr/local/mysql/mysql-8.0/data -R

7、在 /etc/profile 中添加环境变量  并执行 source /etc/profile

  export PATH=$PATH:/usr/local/mysql/mysql-8.0/bin:/usr/local/mysql/mysql-8.0/lib

 8、配置 /etc/my.cnf

[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 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   [mysqld_safe] log-error=/usr/local/mysql/data/mysql.log pid-file=/usr/local/mysql/data/mysql.pid

9、在/usr/local/mysql/mysql-8.0/bin目录下执行  执行初始化指令

  ./mysqld --user=mysql --basedir=/usr/local/mysql/mysql-8.0 --datadir=/usr/local/mysql//mysql-8.0/data/ --initialize

Linux系统安装Mysql8.0流程与遇到的问题

 

  操作成功后会给出临时密码:%8s/H*uB!(ed

10、进入/usr/local/mysql/mysql-8.0目录   复制mysql执行文件 并赋予权限

  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

11、创建文件夹 mkdir /var/lib/mysql  并授权

  chown -R mysql:mysql /var/lib/mysql/

12、启动MySQL

  service mysql start

  # SUCCESS 则表示成功

13、用户登录

  mysql -uroot -p

  此时输入 初始化操作给出的密码就可以登录了

  password:%8s/H*uB!(ed (这里输入之前保存的临时密码即可)

Linux系统安装Mysql8.0流程与遇到的问题

 

 14、修改密码 

  ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';

  flush privileges;#刷新权限

15、设置远程连接

use mysql; # 选择数据库

mysql> create user 'root'@'%' identified by 'password';

mysql> grant all privileges on *.* to 'root'@'%' with grant option;

mysql> flush privileges;

 

16、到这里,整个安装过程结束。

***遇到的问题

1、权限问题

Linux系统安装Mysql8.0流程与遇到的问题

 解决方法:chown mysql:mysql /var/log/mysql/mysql.log

2、data文件夹已存在 删掉data文件夹即可  初始化时自动创建

Linux系统安装Mysql8.0流程与遇到的问题

 3、MySQL登录

Linux系统安装Mysql8.0流程与遇到的问题

   这里需要输入,之前保存的临时密码,其他任何值都会报错!