学习使用,安装小一点的包,生产中不建议安装5.5版本
一、下载RPM包
https://downloads.mysql.com/archives/community/
二、命令安装
# rpm -ivh MySQL-server-5.5.62-1.el7.x86_64.rpm
三、解决依赖性
直接安装出现依赖性的错误,提示如下:
[root@localhost upload]# rpm -ivh MySQL-server-5.5.62-1.el7.x86_64.rpm
警告:MySQL-server-5.5.62-1.el7.x86_64.rpm: 头V4 DSA/SHA1 Signature, 密钥 ID cd2efd2a: NOKEY
错误:依赖检测失败:
perl(Data::Dumper) 被 MySQL-server-5.5.62-1.el7.x86_64 需要
提示:perl(Data::Dumper) 被 MySQL-server-5.5.62-1.el7.x86_64 需要
[root@localhost upload]# yum install -y perl
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.163.com
软件包 4:perl-5.16.3-286.el7.x86_64 已安装并且是最新版本
无须任何处理
yum install -y perl没什么用,网上查找资料得知需要安装的是autoconf
# yum -y install autoconf
还需要安装
yum install -y libaio
接下来又提示:
# rpm -ivh MySQL-server-5.5.62-1.el7.x86_64.rpm
警告:MySQL-server-5.5.62-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
file /usr/share/mysql/charsets/README from install of MySQL-server-5.5.62-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
file /usr/share/mysql/charsets/Index.xml from install of MySQL-server-5.5.62-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
file /usr/share/mysql/charsets/armscii8.xml from install of MySQL-server-5.5.62-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
file /usr/share/mysql/charsets/ascii.xml from install of MySQL-server-5.5.62-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
file /usr/share/mysql/charsets/cp1250.xml from install of MySQL-server-5.5.62-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
file /usr/share/mysql/charsets/cp1251.xml from install of MySQL-server-5.5.62-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
file /usr/share/mysql/charsets/cp1256.xml from install of MySQL-server-5.5.62-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
。
。
。
原因是和centos7自带的mariadb冲突,我们把它卸载了。(这一步非常重要)
卸载mariadb
# rpm -qa | grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
# rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps
再进行安装:
# rpm -ivh MySQL-server-5.5.62-1.el7.x86_64.rpm
警告:MySQL-server-5.5.62-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:MySQL-server-5.5.62-1.el7 ################################# [100%]
安装成功
四、验证是否安装成功
[root@localhost home]# mysqladmin --version
mysqladmin Ver 8.42 Distrib 5.5.62, for Linux on x86_64
[root@localhost home]# cat /etc/passwd|grep mysql
mysql:x:996:993:MySQL server:/var/lib/mysql:/bin/bash
[root@localhost home]# cat /etc/group|grep mysql
mysql:x:993:
五、启动服务
systemctl start mysql #启动服务
chkconfig mysql on #设置开机自启动
六、配置密码
安装成功后的Mysql是没有密码的,这样不安全。我们来配置密码:
/usr/bin/mysqladmin -u root password
New password:
Confirm new password:
password后面输入你的密码即可
七、登录数据库并配置远程访问
1、登入:
[root@localhost home]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.62 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
2、配置字符集为UTF8
拷贝/usr/share/mysql/my-huge.cnf文件到/etc/下并重命名为:my.cnf
cp /usr/share/mysql/my-huge.cnf /etc/my.cnf
编辑/etc/my.cnf 文件配置字符集信息
#编辑命令
vim /etc/my.cnf
#在对应位置加入如下内容并保存退出
[client]
default-character-set=utf8
[mysqld]
character_set_server=utf8
character_set_client=utf8
collation-server=utf8_general_ci
[mysql]
default-character-set=utf8
3、配置远程访问:
#登入并输入密码
mysql -uroot -p
#切换默认库
use mysql;
#查看默认的主机账号信息
select user,host from user;
#修改主机访问权限
update user set host='%' where user='root' and host='localhost';
#刷新配置
flush privileges;
#退出MySQL服务器
exit;
quit;
#重新启动MySQL
systemctl restart mysql;
——————————————————————————————————
安装总结:
一、依赖性:net-tools.x86_64,libaio.x86_64,perl.x86_64三个依赖,使用yum安装即可。
yum -y install perl.x86_64
yum -y install libaio.x86_64
yum -y install net-tools.x86_64
二、卸载centos7自带的mariadb
# rpm -qa | grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
# rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps
参考资料:
https://blog.csdn.net/weixin_44187730/article/details/85693563
https://blog.csdn.net/Ep_Little_prince/article/details/102636447