1、下载安装文件$ wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
2、解压安装文件$ tar -zxvf mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
3、移动文件到/usr/local/目录下$ mv mysql-8.0.11-linux-glibc2.12-x86_64 /usr/local/mysql
4、创建数据存储文件夹$ mkdir /usr/local/mysql/data
5、创建用户及用户组# 用户组
$ groupadd mysql
# 用户 (用户名/密码)
$ useradd -g mysql mysql
# 授权
$ chown -R mysql.mysql /usr/local/mysql/
6、初始化数据库# /usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --initialize
7、建立MySQL服务$ cp -a ./support-files/mysql.server /etc/init.d/mysql # 若mysqld,以下mysql相应的修改mysqld,如下图所示
$ chmod +x /etc/init.d/mysql
$ chkconfig --add mysql
# 检查服务是否生效
$ chkconfig --list mysql
8、启动mysql服务# 启动
$ service mysql start;
# 查看启动状态
$ service mysql status;
9、client链接mysql$ mysql -u root -p
如果提示错误ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO),root账户没有设置密码,可以在安装账户下设置密码#关闭服务
$ service mysql stop
#安全模式登录
./mysqld_safe --skip-grant-tables
#登录mysql
$ ./mysql -u root
设置密码
mysql8.0设置的密码不一样,命令如下ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY'Test@123_sh';
如果提示错误ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
可以先执行mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY'Test@123_sh';
Query OK, 0 rows affected (0.08 sec)
密码添加成功
可以登录使用mysql了