Centos7离线安装mysql8
linux版本:Centois7
mysql版本:mysql-8.0.16 主要版本要一致
1、下载
下载地址 :https://dev.mysql.com/downloads/mysql/
选择:
2、将tar包上传至服务器
3、删除原来的mariadb
先查看一下是否已经安装了,命令:rpm -qa|grep mariadb
删除mariadb,命令:rpm -e --nodeps mariadb-libs
4、解压mysql离线安装包
cd /home/soft tar -xvf mysql-8.0.16-2.el7.x86_64.rpm-bundle.tar
解压后包含如下rpm包:
mysql-community-libs-8.0.16-2.el7.x86_64.rpm mysql-community-embedded-compat-8.0.16-2.el7.x86_64.rpm mysql-community-devel-8.0.16-2.el7.x86_64.rpm mysql-community-server-8.0.16-2.el7.x86_64.rpm mysql-community-libs-compat-8.0.16-2.el7.x86_64.rpm mysql-community-client-8.0.16-2.el7.x86_64.rpm mysql-community-common-8.0.16-2.el7.x86_64.rpm mysql-community-test-8.0.16-2.el7.x86_64.rpm
5、安装rpm
逐个安装,命令如下: 【必须安装】 rpm -ivh mysql-community-common-8.0.16-2.el7.x86_64.rpm rpm -ivh mysql-community-libs-8.0.16-2.el7.x86_64.rpm rpm -ivh mysql-community-client-8.0.16-2.el7.x86_64.rpm rpm -ivh mysql-community-server-8.0.16-2.el7.x86_64.rpm 【非必须安装】 rpm -ivh mysql-community-libs-compat-8.0.16-2.el7.x86_64.rpm rpm -ivh mysql-community-embedded-compat-8.0.16-2.el7.x86_64.rpm rpm -ivh mysql-community-devel-8.0.16-2.el7.x86_64.rpm rpm -ivh mysql-community-test-8.0.16-2.el7.x86_64.rpm
错误1:
warning: mysql-community-devel-8.0.16-2.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY error: Failed dependencies: pkgconfig(openssl) is needed by mysql-community-devel-8.0.16-2.el7.x86_64
解决方法1:
yum install openssl-devel.x86_64 openssl.x86_64 -y
错误2:
warning: mysql-community-test-8.0.16-2.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY error: Failed dependencies: perl(Data::Dumper) is needed by mysql-community-test-8.0.16-2.el7.x86_64 perl(JSON) is needed by mysql-community-test-8.0.16-2.el7.x86_64
解决方法2:
yum install perl.x86_64 perl-devel.x86_64 -y yum install perl-JSON.noarch -y yum -y install autoconf
6、mysql服务指令
mysql -V 看长安装版本
systemctl status mysqld 查看状态
systemctl start mysqld 启动mysql
systemctl stop mysqld 停止mysql
7、初始化mysql
关掉mysql:
systemctl stop mysqld
初始化先先编辑my.cnf文件:
vim /etc/my.cnf
在文件末尾追加内容:
#无密码登录 skip-grant-tables #忽略大小写 lower_case_table_names=1
最后初始化:
mysqld --initialize --console --lower-case-table-names=1
8、目录授权
chown -R mysql:mysql /var/lib/mysql/
授权完启动mysql:
systemctl start mysqld
9、mysql操作
登录mysql:
mysql -u root -p 注意:直接回车掉过密码输入
登录如果操作报错:
--必须先执行 flush privileges,否则会报The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
需要先执行指令:
flush privileges;
修改密码:
alter USER 'root'@'localhost' IDENTIFIED BY '123456';
授权远程连接:
show databases; use mysql; select host, user, authentication_string, plugin from user;
update user set host = "%" where user='root'; select host, user, authentication_string, plugin from user; flush privileges;
尝试远程登录:
远程登录前需要指定防火墙访问端口,这步骤这里先忽略,不动可以去参考 url
解决办法:
mysql -u root -p(回车后,输入更改后的密码123456) use mysql; alter USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; flush privileges;
最后记得,把etc/my.cnf 中的 skip-grant-tables 注释掉,重启mysql就可以使用了。