1.如果已安装成功 则需要卸载前请先关闭Mysql服务 命令:service mysql stop
2.使用 rpm 命令的方式查看已安装的mysql 命令:rpm -qa|grep mysql
3.使用yum安装的Mysql需要先进行清除 命令:yum remove mysql mysql-server mysql-libs mysql-server
4.再次查询是否有剩余文件 命令:rpm -qa|grep mysql
5.使用过rpm -ev +对应文件名 删除剩余文件 命令:
rpm -ev mysql80-community-release-el7-1.noarch
rpm -ev mysql-community-client-plugins-8.0.25-1.el7.x86_64
rpm -ev mysql-community-common-8.0.25-1.el7.x86_64
6.查询是否还存在Mysql相关遗漏文件(有则使用对应删除命令删除)
mysql官网:https://dev.mysql.com/downloads/mysql/
将下载的mysql上传打linux
[root@rsyncClient local]# tar -zxvf mysql-8.0.18-el7-x86_64.tar.gz -C /usr/local/
[root@rsyncClient local]# mv mysql-8.0.18-el7-x86_64/ mysql
[root@rsyncClientopt]# cd /usr/local/mysql/
[root@rsyncClient mysql]# mkdir data
[root@rsyncClient local]# groupadd mysql
[root@rsyncClient local]# useradd -g mysql mysql
[root@rsyncClient local]# chown -R mysql.mysql /usr/local/mysql/
[root@iZbp1iwvf9mlryt1ml8tdrZ mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --lower-case-table-names=1
在mysql/support-files创建文件my-default.cnf
[root@rsyncClient support-files]# cd /usr/local/mysql/support-files/
[root@rsyncClient support-files]# touch my-default.cnf
复制配置文件到/etc/my.cnf
[root@rsyncClient support-files]# cp -a ./my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
编辑my.cnf
[client]
port=3306
socket=/tmp/mysql.sock
[mysqld]
port=3306
user=mysql
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
编辑 / etc/profile 文件
[root@rsyncClient mysql]# vim /etc/profile
#配置mysql环境变量
PATH=/data/mysql/bin:/data/mysql/lib:$PATH
export PATH
#让其生效
[root@rsyncClient mysql]# source /etc/profile
#看环境变量是否生效
[root@rsyncClient mysql]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@rsyncClient mysql]# systemctl start mysqld
启动失败报错1:
Job for mysql.service failed because the control process exited with error code. See “systemctl status mysql.service” and “journalctl -xe” for details.
解决方案:
[root@rsyncClient ~]# chown mysql:mysql -R /usr/local/mysql/
启动失败报错2:
[root@rsyncClient mysql]# service mysql start
/etc/init.d/mysql: ./bin/my_print_defaults: /lib/ld-linux.so.2: bad ELF interpreter: No such file or
directory Starting MySQL. ERROR! The server quit without
updating PID file (/var/lib/mysql/rsyncClient.pid).
去这个目录下面查看 cat/usr/local/mysql/data/rsyncClient.err错误,对应的的解决,这里错误是因为my.conf配置错误
启动失败报错3:
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file:
No such file or directory
[root@rsyncClient init.d]# yum install libncurses.so.5
以这个为例,如果缺少这样依赖,直接用yum安装
启动失败报错4:
[root@rsyncClient data]# mysql -uroot -p
Enter password:
ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded:
/usr/lib/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory
身份验证插件不能加载
解决办法:
[root@rsyncClient lib]# vim /etc/my.cnf
在这个[mysqld]下添加一行:
default_authentication_plugin=mysql_native_password
如果忘记了密码在加上:
skip-grant-tables(跳过密码验证)等设置了密码就去掉
启动mysql服务:
#systemctl start mysqld.service
停止mysql服务
#systemctl stop mysqld.service
重启mysql服务
#systemctl restart mysqld.service
查看mysql服务当前状态
#systemctl status mysqld.service
设置mysql服务开机自启动
#systemctl enable mysqld.service
停止mysql服务开机自启动
#systemctl disable mysqld.service
/usr/local/mysql/bin/mysql -u root -p password
修改mysql的默认初始化密码
alter user’root’@‘localhost’ identified by’root’;
create user ‘yehui’@‘localhost’ identified by ‘yehui’;
#给所有远程登录的进行授权,此方式已经报错了
grant all privileges on . to ‘root’@‘%’ identified by ‘root’ with grant option;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘identified by ‘root’ with grant option’ at line 1
update user set Host=‘%’ where User=‘root’;
grant replication slave on . to’yehui’@‘localhost’;
#刷新
flush privileges;
#权限问题可以参考https://www.cnblogs.com/php-linux/p/11561300.html
复制代码
12.防火墙问题
[root@rsyncClient data]# firewall-cmd --permanent --zone=public --add-port=3306/tcp #允许访问
success
[root@rsyncClient data]# firewall-cmd --reload #重新加载
success
[root@rsyncClient data]# firewall-cmd --permanent --zone=public --query-port=3306/tcp #查看是否开通访问权限
yes
$ docker pull mysql:8.0.16
在宿主机创建放置mysql的配置文件的目录和数据目录,并且进行授权
$ mkdir -p /usr/mysql/conf /usr/mysql/data
$ chmod -R 755 /usr/mysql/
在上面创建的配置文件目录/usr/mysql/conf下创建MySQL的配置文件my.cnf
$ vim /usr/mysql/conf/my.cnf
添加以下内容到上述创建的配置文件中
[client]
#socket = /usr/mysql/mysqld.sock
default-character-set = utf8mb4
[mysqld]
#pid-file = /var/run/mysqld/mysqld.pid
#socket = /var/run/mysqld/mysqld.sock
#datadir = /var/lib/mysql
#socket = /usr/mysql/mysqld.sock
#pid-file = /usr/mysql/mysqld.pid
lower_case_table_names=1
datadir = /usr/mysql/data
character_set_server = utf8mb4
collation_server = utf8mb4_bin
secure-file-priv= NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Custom config should go here
!includedir /etc/mysql/conf.d/
$ docker run --restart=unless-stopped -d --name mysql -v /usr/mysql/conf/my.cnf:/etc/mysql/my.cnf -v /usr/mysql/data:/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:8.0.16
参数解释:
-v : 挂载宿主机目录和 docker容器中的目录,前面是宿主机目录,后面是容器内部目录-d : 后台运行容器
-p 映射容器端口号和宿主机端口号
-e 环境参数,MYSQL_ROOT_PASSWORD设置root用户的密码
执行上述命令后,执行查询容器的命令就可以看到创建的mysql容器
$ docker ps -a
结果如下所示:
上述虽然安装好了mysql,但是使用远程的Navicat连接时提示错误,不能正确连接mysql,此时需要修改按照下面说的步骤修改一下mysql的密码模式以及主机等内容才可以。
$ docker exec -it mysql /bin/bash
$ mysql -uroot -p
$ mysql> use mysql
$ mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '新密码';
如果执行失败修改user表中的Host: update user set Host=‘%’ where User=‘root’;
说明: % 代表任意的客户端,可替换成具体IP地址。再执行上面SQL;
注意:
mysql_native_password,mysql8.x版本必须使用这种模式,否则navicate无法正确连接
$ mysql> flush privileges
经过以上步骤,再次远程使用Navicat连接数据库时就可以正常连接了。