阿里云安装Mysql数据库

阿里云安装Mysql数据库

网上攻略太多了,很多是不符合自己安装的环境的,所以还是要因具体的环境而定

阿里云服务器 :Linux 3.10.0-693.2.2.el7.x86_64 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Mysql版本 :mysql-5.6.42-linux-glibc2.12-x86_64
下载地址 : MySQL官网


  1. 卸载参考:
    a)查看系统中是否以rpm包安装的mysql
[plain] view plaincopy
[root@linux ~]# rpm -qa | grep -i mysql  
MySQL-server-5.1.49-1.glibc23  
MySQL-client-5.1.49-1.glibc23  

有就卸载

[plain] view plaincopy
[root@linux ~]# rpm -e MySQL-client-5.1.49-1.glibc23  
[root@linux ~]# rpm -e MySQL-server-5.1.49-1.glibc23 

b)查看有没有mysql服务

[plain] view plaincopy
[root@linux ~]# chkconfig --list | grep -i mysql  
mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off  

删除mysql服务

[plain] view plaincopy
[root@linux ~]# chkconfig --del mysql  

c)删除分散mysql文件夹

[plain] view plaincopy
[root@linux ~]# whereis mysql  
mysql: /usr/lib/mysql /usr/share/mysql  

分别删除

[plain] view plaincopy
[root@linux lib]# rm -rf /usr/lib/mysql/  
[root@linux lib]# rm -rf /usr/share/mysql  

通过以上几步,mysql应该已经完全卸载干净了

2.下载安装
参考官方:使用通用二进制文件在Unix / Linux上安装MySQL

shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> scripts/mysql_install_db --user=mysql
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server

这里报了个错

# scripts/mysql_install_db --user=mysql
FATAL ERROR: please install the following Perl modules before executing scripts/mysql_install_db:
Data::Dumper

解决方法 :安装autoconf库
命令:yum-y install autoconf //此包安装时会安装Data:Dumper模块
或参考:Mysql官方的Perl安装说明

# yum-y install autoconf
-bash: yum-y: command not found
# rpm -qa |grep yum
yum-metadata-parser-1.1.4-10.el7.x86_64
yum-plugin-fastestmirror-1.1.31-42.el7.noarch
yum-3.4.3-154.el7.centos.noarch
# yum
  ...
# yum install autoconf
 ...

这里差点被坑,以为yum没有安装,去掉-y安装,不太懂为什么

继续报错

# scripts/mysql_install_db --user=mysql
Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

下载

# yum install libaio* -y 

参考:提前参考 MySQL基准测试套件

3.使用密码登录mysql账号:mysql -uroot -p
修改root密码:SET PASSWORD = PASSWORD('123456');

4.开启远程访问

mysql -uroot –p123456

设置远程访问(使用root密码):
grant all privileges on *.* to 'root' @'%' identified by '123456'; 
flush privileges;

防火墙打开3306端口
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
/etc/rc.d/init.d/iptables save
/etc/init.d/iptables status

这篇参考也可以看看,很有帮助:
【MySQL】Linux下MySQL 5.5、5.6和5.7的RPM、二进制和源码安装-博客-云栖社区-阿里云

你可能感兴趣的:(阿里云安装Mysql数据库)