1.下载mysql 8
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz
2.输入指令解压到当前目录
tar -xvf mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz
3.创建安装目录:
mysql文件夹 , 在mysql目录下创建data文件夹,复制解压文件至mysql文件中
mkdir /usr/local/mysql8
mkdir /usr/local/mysql8/data
mv mysql-8.0.30-linux-glibc2.12-x86_64/* /usr/local/mysql8
4.mysql初始化
进入bin目录执行mysqld文件进行初始化
cd bin
./mysqld --user=root --basedir=/usr/local/mysql8 --datadir=/usr/local/mysql8/data --initialize
vim /etc/my.cnf
[mysqld]
user=root
datadir=/usr/local/mysql8/data
basedir=/usr/local/mysql8
port=3306
max_connections=200
max_connect_errors=10
character-set-server=utf8
default-storage-engine=INNODB
default_authentication_plugin=mysql_native_password
lower_case_table_names=1
group_concat_max_len=102400
[mysql]
default-character-set=utf8
[client]
port=3306
default-character-set=utf8
5.添加mysqld服务
返回mysql-8.0目录下,添加mysqld服务到系统
cd ..
cp -a ./support-files/mysql.server /etc/init.d/mysql
6.启动mysql
service mysql start
扩展
创建用户组以及用户
创建mysql组,再创建mysql用户并将mysql用户添加到组中
groupadd mysql
useradd -g mysql mysql
授权用户
将mysql文件夹的所有者和所有组都改为mysql
chown -R mysql.mysql /usr/local/mysql-8.0
授权以及添加服务
chmod +x /etc/init.d/mysql
chkconfig --add mysql
忘记密码
skip-grant-tables
windows安装mysql
1. 官网下载Mysql8安装包
2. 安装后cmd管理员运行
#服务初始化**
cd /安装目录/bin/
mysqld --install
mysqld --initialize --console
#启动服务
net start mysql
忘记密码:
my.cnf中mysqld中添加一行
skip-grant-tables
重启mysql
密码置空
UPDATE user SET authentication_string='' WHERE user='root';
删除skip-grant-tables 并重启mysql
修改密码
//设置密码
alter user 'root'@'localhost' identified with mysql_native_password by 'admin';
//修改密码有效期
ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
flush privileges;
重启异常处理
Authentication plugin ‘caching_sha2_password’ cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object
//修改配置文件
vi my.cnf
default_authentication_plugin=mysql_native_password
Can’t connect to local MySQL server through socket '/var/lib/mysql/mysql.sock
//修改配置,添加软连接
vi my.cnf
socket=/tmp/mysql.sock
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
ERROR! The server quit without updating PID file (/usr/local/mysql8/data/cactiserver.pid).
//添加用户和角色
# groupadd mysql
# useradd -g mysql mysql
# chown -R mysql.mysql /usr/local/mysql
# chmod +x /etc/init.d/mysql
# chkconfig --add mysql
强制修改密码
The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
1. 添加skip-grant-tables,无密码登录。
2. 另起liunx窗口,修改密码登录模式:删除skip-grant-tables
3. 原窗口,强制修改密码