mysql8.0安装

1.下载

mysql-8.0.15-linux-glibc2.12-x86_64.tar.xz

2.解压

tar -xvf mysql-8.0.15-linux-glibc2.12-x86_64.tar.xz

mv mysql-8.0.15-linux-glibc2.12-x86_64 mysql

mv mysql /usr/local

cd /usr/local/mysql

mkdir data

3.编辑 my.cnf 

vi /etc/my.cnf

文件内容为:

[client]
port=3306
socket=/tmp/mysql/mysql.sock

[mysqld]
port=3306
user=mysql
socket=/tmp/mysql/mysql.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
log-error=error.log
default_authentication_plugin=mysql_native_password
transaction_isolation = READ-COMMITTED
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
lower_case_table_names = 1
sql-mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
#skip-grant-tables

4.创建用户

groupadd mysql

useradd -g mysql mysql

5.更改目录权限

chown -R mysql:mysql /tmp/mysql

chown -R mysql:mysql /usr/local/mysql

chmod -R 755 /tmp/mysql /usr/local/mysql

6. 初始化

cd /usr/local/mysql

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

7.初始化密码

初始化时并没有出现 初始密码,因此需要修改密码。

注释 skip-grant-tables,可以使用无密码登录

启动 mysql

./support-files/mysql.server start

1.清空密码

use mysql;

update user set authentication_string='' where user='root';  

2.无密码登录

mysql -u root -p  

输入密码是直接回车。

ALTER user 'root'@'localhost' IDENTIFIED BY 'root';

 8 设置自动启动

cd support-files/

cp mysql.server /etc/init.d/mysql

chmod 755 /etc/init.d/mysql 

cd /etc/init.d

 chkconfig --add mysql

chkconfig --level 345 mysql on

mysql restart

9.创建用户

create user 'username'@'%' identified by 'password';

10.授权该用户

grant all privileges on *.* to 'username'@'localhost' with grant option;

FLUSH PRIVILEGES;

原文地址:https://www.cnblogs.com/fangdecheng/p/14779572.html