Linux目前存在大量的发行版,不同的发行版可能软件安装方式不同,或者软件管理工具也不一样(图
Ubuntu和CentOS的包管理工具分别是:apt/apt-get和yum)。
APT方式安装
在ubuntu系统的apt软件仓库中,默认存在MySQL数据库,所以直接使用apt命令就可以安装。
使用命令:
apt/apt-get install mysql-server mysql-client
过程中,可能要输入root的密码
如果没有出现root配置密码的界面,则安装成功,在 /etc/mysql/debian.cnf下查找密码
mariadb
mariadb是MySQL的主要分支(有兴趣的可以看看这个故事),因此mariadb就是MySQL,现在有很多
公司就是使用mariadb。
CentOS YUM中存在mariadb的源,因此安装很是简单(如果在安装CentOS时选择了,可能已经默认安
装了)。
安装过程:
1、如果使用官方源,直接yum install MariaDB-server MariaDB-client -y命令安装即可。
2、建议使用国内的源:添加mariadb10.2的国内yum源,之前添加的是国外的源,安装很耗时,因此可
以使用国内yum源,通过这个源安装较快。
vim /etc/yum.repos.d/Mariadb.repo
添加以下内容:
[mariadb]
name = MariaDB
baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.2/centos7-amd64
gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
官方yum源(国内安装较慢):
#MariaDB 10.2 CentOS repository list - created 2018-06-06 03:42 UTC
#http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
3、清除yum源缓存数据
yum clean all
4、安装mariadb10.2
yum install MariaDB-server MariaDB-client -y
5、启动并添加开机自启:
systemctl start mariadb.service
systemctl enable mariadb.service
6、安全插件初始化密码(如果安装系统时已经安装了MariaDB,则直接初始化密码即可)
/usr/bin/mysql_secure_installation
一般建议按以下进行配置:
Enter current password for root (enter for none): Just press the Enter button
Set root password? [Y/n]: Y
New password: your-MariaDB-root-password
Re-enter new password: your-MariaDB-root-password
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: n
Remove test da