Linux安装Mysql8.0.11
0. 安装环境
1. 下载安装包
- 方式一:百度网盘下载
链接:https://pan.baidu.com/s/11t_JXUp-SXRaioNDvdltNg
提取码:uzyj
- 方式二:在线下载
1 #下载安装包到/usr/local/src/ 2 wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
2. 安装
1 cd /usr/local/src/ 2 3 #解压 4 tar -zxvf mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz 5 6 #拷贝到/usr/local 7 mv /usr/local/src/mysql-8.0.11-linux-glibc2.12-x86_64 /usr/local/ 8 9 #修改名称 10 mv ./mysql-8.0.11-linux-glibc2.12-x86_64 mysql-8.0.11 11 12 #创建存放数据文件夹 13 mkdir /usr/local/mysql-8.0.11/data 14 15 #创建用户及用户组 16 groupadd mysql 17 useradd -g mysql mysql 18 19 #授权 20 chown -R mysql.mysql /usr/local/mysql-8.0.11 21 22 #初始化数据库(记录临时密码) 23 cd /usr/local/mysql-8.0.11/ 24 ./bin/mysqld --user=mysql --lower-case-table-names=1 --basedir=/usr/local/mysql-8.0.11/ --datadir=/usr/local/mysql-8.0.11/data/ --initialize ; 25 26 #配置my.cnf 27 vi /etc/my.cnf 28 #在[mysqld]下添加 29 basedir=/usr/local/mysql-8.0.11 30 datadir=/usr/local/mysql-8.0.11/data 31 socket=/tmp/mysql.sock 32 character-set-server=utf8 33 lower-case-table-names=1 34 35 #建立Mysql服务 36 cp -a ./support-files/mysql.server /etc/init.d/mysql 37 chmod +x /etc/init.d/mysql 38 chkconfig --add mysql 39 40 #检查服务是否生效 41 chkconfig --list mysql 42 43 #启动、停止、重启 44 service mysql start 45 service mysql stop 46 service mysql restart
3. 登录Mysql修改密码并设置权限
1 #登录(使用临时密码) 2 mysql -uroot -p 3 4 #若出现-bash: mysqldump: 未找到命令 5 ln -s /usr/local/mysql-8.0.11/bin/mysql /usr/bin 6 7 #修改密码 8 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new password'; 9 10 #配置远程连接 11 vi /etc/my.cnf 12 13 #在[mysqld]在增加 14 default_authentication_plugin=mysql_native_password 15 16 #修改root权限 17 use mysql 18 update user set host ='%' where user='root'; 19 alter user 'root'@'%' identified with mysql_native_password by 'new password'; 20 flush privileges;