mysql8安装
https://downloads.mysql.com/archives/community/
1、下载mysql8 的网址 https://dev.mysql.com/downloads/mysql/
选择你服务器上对应的版本 我选择的就是x86 Linux7版本
2、上传到服务器并解压
tar -xvf mysql-8.0.29-1.el7.x86_64.rpm-bundle.tar
如果报错:
tar: 归档文件中异常的 EOF
tar: 归档文件中异常的 EOF
tar: Error is not recoverable: exiting now
解决方法:
文件问题
我这里重新上传就ok了
下面执行的命令均在home目录下
首先我需要查看centos7下面的mariadb 包,这个会跟mysql安装发生冲突,我们先进行删除
rpm -qa|grep mariadb
rpm -e --nodeps mariadb-libs
3、下载依赖
rpm -ivh mysql-community-common-8.0.29-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.0.29-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.29-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.29-1.el7.x86_64.rpm
rpm -ivh mysql-community-icu-data-files-8.0.29-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.29-1.el7.x86_64.rpm
如果执行最好一句命令是有报错的话,可能是缺少了一个依赖,也可以自行百度错误信息。我这就写一下我下载的依赖。
yum install libaio
如果还报错的话,执行 rpm -ivh mysql-community-server-8.0.29-1.el7.x86_64.rpm --nodeps --force
4、启动mysql和修改密码
依赖包下来好了以后,实例化一下mysql
mysqld --initialize --console
如果报错mysqld: error while loading shared libraries: libssl.so.10: cannot open shared object file: No such file or directory
则安装一下: yum -y install compat-openssl10;
然后启动mysql
systemctl命令兼容了service
即systemctl也会去/etc/init.d目录下,查看,执行相关程序
systemctl start mysqld
service mysqld start
chown mysql:mysql /var/lib/mysql -R;
查看启动状态
systemctl status mysqld.service
如果启动报错:
Redirecting to /bin/systemctl restart mysqld.service
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
则执行:
chown mysql:mysql /var/lib/mysql -R;
mysql启动成功,查看mysql的临时密码
cat /var/log/mysqld.log|grep localhost
用临时密码登陆以后, 修改mysql密码,123456替换成你自己需要的密码。
alter user 'root'@'localhost' identified by '123456';
注意:第一次安装mysql的时候,密码太过简单,可能会报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
此时需要修改一个难一点的密码
修改加密规则:
update user set authentication_string=password('新密码') where user='root';
提交:
flush privileges;
参考链接:
https://blog.csdn.net/qq_43339903/article/details/125773490
开启mysql外部远程访问权限
MySQL8.0之前:
GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY '123456';(其中123456是数据库密码)
FLUSH PRIVILEGES;
如果运行外部访问语句之后报错:
grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘123456‘ with grant optio
这是mysql的版本问题,这条语句适用于MySQL8.0之前
mysql8.0及以上版本需要使用以下语句:
create user root@'%' identified by '123456';
grant all privileges on *.* to root@'%' with grant option;
FLUSH PRIVILEGES;
卸载mysql:
卸载mysql:
1、首先查看mysql的安装情况
rpm -qa|grep -i mysql
显示之前安装了:
MySQL-client-5.5.25a-1.rhel5
MySQL-server-5.5.25a-1.rhel5
2、停止mysql服务,并删除包
删除命令:rpm -e –nodeps 包名
rpm -ev MySQL-client-5.5.25a-1.rhel5
rpm -ev MySQL-server-5.5.25a-1.rhel5
如果提示依赖包错误,则使用以下命令尝试
rpm -ev MySQL-client-5.5.25a-1.rhel5 --nodeps
如果提示错误:error: %preun(xxxxxx) scriptlet failed, exit status 1
则用以下命令尝试:
rpm -e --noscripts MySQL-client-5.5.25a-1.rhel5
3、查找之前老版本mysql的目录、并且删除老版本mysql的文件和库
查找目录
find / -name mysql
删除对应的mysql目录
rm -rf 目录
注意:卸载后/etc/my.cnf不会删除,需要进行手工删除
rm -rf /etc/my.cnf
4、再次查找机器是否安装mysql
rpm -qa|grep -i mysql
无结果,说明已经卸载彻底,接下来直接安装mysql即可。
参考链接:
https://m.php.cn/article/419550.html
命令行执行sql文件: