Loading... ## And 1.获取RPM包 自建服务器暂时拆了,不提供自建备份下载,自行前往[mysql.com](https://mysql.com)下载压缩包解压,贴个图:  windows的就安装程序,下载好后双击安装完事,自行研究。 解压后的包:  将文件上传到linux内  ## And 2.安装mysql 以上,可以看到有10个rpm包,安装实际上并不需要全部使用上,当然可以直接使用`rpm -ivh ./*.rpm --nodeps --force`一次性将rpm包全都安装上:  单独安装所需要的包的话就得单个顺序的安装,如下四个包即可: ```shell rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm ```  这里安装时候报错`from install of mysql-community-common-5.7.28-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64`,需要先卸载一下`mariadb-libs`组件: 这里可以使用`rpm -qa`或者`yum list installed`来查看一下自带相关组件: ### And 2.1.卸载组件 ```shell yum list installed |grep mariadb rpm -qa |grep mariadb ```  可以使用`yum remove`或者`rpm -ev`来卸载: ```shell yum remove mariadb-libs.x86_64 -y ```  查看一下是否卸载完成:  ```shell rpm -ev mariadb-libs-5.5.68-1.el7.x86_64 ``` 这里rpm卸载时候提示`postfix`被需要:`错误:依赖检测失败: libmysqlclient.so.18()(64bit) 被 (已安裝) postfix-2:2.10.1-9.el7.x86_64 需要 libmysqlclient.so.18(libmysqlclient_18)(64bit) 被 (已安裝) postfix-2:2.10.1-9.el7.x86_64 需要`。  这里就先卸载一下`postfix`再卸载`mariadb`: ```shell rpm -ev postfix-2:2.10.1-9.el7.x86_64 rpm -ev mariadb-libs-5.5.68-1.el7.x86_64 ```  ### And 2.2.继续单独顺序安装 ```shell rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm ```  ```shell rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm ```  ```shell rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm ```  ```shell rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm ```  安装完成。。。 ## And 3.启动、修改、远程mysql 安装好后需要先启动一次mysqld服务后才能有默认密码 可以先启动添加到开机自启后再重设一下mysql的root用户密码。 ### And 3.1.添加到开机 ```shell systemctl status mysqld ``` 可以看到mysql处于关闭状态。  给加一下开机自启再开一下: ```shell systemctl enable mysqld systemctl start mysqld systemctl status mysqld ```  ### And 3.2.mysql修改 这里将修改mysql的root用户的默认密码,并且修改其可以远程登录访问。 以上mysq启动完成后,我们`cat`出mysql的日志文件可以看到mysq安装的默认密码。 ```shell cat /var/log/mysqld.log ```  直接全打印出来会有很多内容,可以使用grep检索一下内容: ```shell grep password /var/log/mysqld.log ```  由于默认密码有特殊字符会被shell终端解析,所以-p后不输入密码,提示密码输入处输入 ```shell mysql -uroot -p ```  登录mysql后先修改一下root的密码: ```mysql set password for root@localhost = PASSWORD('123456'); ``` 这里报错说密码安全策略不符合  先查看一下默认的密码策略: ```mysql show variables like "validate_password%"; ``` 提示需要用`alter uaer`重设一下密码  ```mysql alter user root@localhost identified by '123456'; ``` 同样提示需要遵循密码策略  那就先设个复杂密码,后面再修改就行 ```mysql set password for root@localhost = PASSWORD('P@ssword1.'); ```  修改完密码后回到查看密码策略: ```mysql show variables like 'validate_password%'; ``` 可以看到密码策略的设置项,我们要修改的有密码等级`policy`和密码长度`length`  将上面对应的两行记下: `validate_password_policy` `validate_password_length` exit退出mysql回到shell终端,编辑`my.cnf`配置: ```shell vi /etc/my.cnf ``` 在“[mysqld]”下加入上面记录的两行,并添加如下图的参数:  保存退出,重启一下mysql服务 ```shell service mysqld restart ```  再次登录到mysql查看密码策略设置,可以看到配置生效了:  再次修改密码为:“123456”:  查看一下当前mysql里有哪几个用户: ```mysql select host,user,password from mysql.user; ``` 这里会报没有‘password’列,是因为mysql5.7开始就不再使用`password`来存密码md5,改用`authentication_string`来存储了: ```mysql select host,user,authentication_string from mysql.user; ``` 可以看到现在的root用户只能本地登录  将root的host修改为`%`允许其可以在任意位置登录使用: ```mysql update mysql.user set host="%" where user="root"; ``` 看到root的host变成了`%`即可。  exit退出mysql,重启一下mysql服务  检查一下防火墙有没有关闭 ```shell systemctl status firewalld.service ``` 开着防火墙,stop给关一下。  ```shell systemctl stop firewalld systemctl status firewalld ```  ## And 3.3.远程连接验证 以上完成后到其他可以ping通其的,带有mysql(客户端)环境的设备上连接测试,如果没有环境,可直接到And 4.2.1安装图形化工具连接测试: 查看mysql服务器的ip:   ```cmd mysql -uroot -p123456 -h 192.168.23.228 ``` 远程连接成功即可。  ## And 4.导入数据库sql文件 ### And 4.1.下载sql文件 ↓↓下载下方zip文件,直接重命名去除`.zip`↓↓ →[重命名去掉 ”.zip“ 使用](https://www.zmzaxg.top/usr/uploads/2023/10/2571417792.zip)← ### And 4.2.导入sql数据文件 这里可以直接使用shell命令导入sql文件到mysql,但这里将使用sql工具导入与使用 #### And 4.2.1.安装SQLyog程序 自建服务器暂时拆了,不提供,自行前往官网安装 #### And 4.2.2.连接mysql 在SQLyog首页  在弹出的连接窗口中填入信息ip和密码,测试连接  没有问题就直接连接,可以保存方便下次连接  #### And 4.2.3.导入sql包 使用SQLyog连接上mysql后,在数据库过滤器中右击  在弹出窗口选择下载保存好上方sql文件的路径执行操作   完成后再次在数据库过滤器右击刷新对象  可以看见多了一个数据库:  依次选择展开就可以看到数据表数据表信息和数据了:  最后修改:2024 年 08 月 30 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 觉得文章有用,可以赞赏请我喝瓶冰露