1. 全部删除系统自带的Mysql/MariaDB
MySQL 已经不再包含在 CentOS 7 的源中,而改用了 MariaDB;MySQL 已经不再包含在 CentOS 7 的源中,而改用了 MariaDB;如果存在,使用:
sudo rpm -e –nodeps mariadb-* //全部删除
或者:
sudo yum remove mysql mysql-server mysql-libs compat-mysql51
2.安装 MariaDB
MariaDB有三种安装方式,源码安装、yum安装、rpm离线包安装。
源码安装很麻烦,还会遇到一些错误,不建议新手使用。所以这里给出yum 和rpm 离线包安装两种方式。
yum 安装
- 添加MariaDB的yum源
sudo vim /etc/yum.repos.d/MariaDB.repo
将下面的内容粘贴进去:
# MariaDB 10.0 CentOS repository list - created 2017-01-04 03:11 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
- 安装 MariaDB
sudo yum install MariaDB-server MariaDB-client
如果想安装其他版本的MariaDB 可以参考 MariaDB官网。 yum源安装的好处是简单方便,通过简单的命令行yum 会帮你全部搞定,但是可能对有些网速不好的朋友来说,yum安装速度会慢的让你无法忍受,还会出现用户退出安装。下面就可以通过rpm 离线包安装
使用RPM包离线安装MariaDB 10.1.20
进入MariaDB官网下载MariaDB需要的RPM包
我是centos7 64 选 10.1.20 —> centos7-amd64—>rpms ,需要下载:
MariaDB-10.1.20-centos7-x86_64-common.rpm
MariaDB-10.1.20-centos7-x86_64-compat.rpm
galera-25.3.19-1.rhel7.el7.centos.x86_64.rpm
jemalloc-3.6.0-1.el7.x86_64.rpm
jemalloc-devel-3.6.0-1.el7.x86_64.rpm
MariaDB-10.1.20-centos7-x86_64-client.rpm
MariaDB-10.1.20-centos7-x86_64-server.rpm
接下来:sudo rpm -ivh XXX.rpm
如果还需要其他依赖,请自行搜索安装^_^
3. 配置MariaDB
After the installation completes, start MariaDB with:
sudo systemctl start mariadb
sudo systemctl start mysql.service
sudo systemctl stop mysql.service
//好使
service mysql start
设置root密码
mysqladmin -u root password ‘root’
登录数据库
mysql -u root -p
如果从其它机器登录:
mysql -h ip地址 -u root -p
PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:
‘/usr/bin/mysqladmin’ -u root password ‘new-password’
‘/usr/bin/mysqladmin’ -u root -h localhost.localdomain password ‘new-password’
Alternatively you can run:
‘/usr/bin/mysql_secure_installation’
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.
Please report any problems at http://mariadb.org/jira
The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB’s strong and vibrant community:
https://mariadb.org/get-involved/