一:安装方式
yum安装(配置yum源)
1- centos官方的yum源
#不同的yum源,软件包的名字也可能不一样,区分大小写 !!!!
2- 阿里云的yum源(下载速度快,但是版本较低)
安装命令如下:
(由于网速问题,我选择用阿里云的精简版)
yum install mariadb-server mariadb
3- mysql官方的yum源 (版本你自由去选择,下载较慢,文件完整性最好)
配置如下方式
1.找到yum仓库目录,创建repo文件
touch /etc/yum.repos.d/mariadb.repo
[root@bogon ~]# cd /etc/yum.repos.d
[root@bogon yum.repos.d]# ls
CentOS-Base.repo epel.repo repobak
[root@bogon yum.repos.d]# touch mariadb.repo
2.添加repo仓库配置 :写入如下内容,指定mysql官方的yum源
[root@bogon yum.repos.d]# vim mariadb.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
3.此时yum会自动的加载这个repo文件,读取内容
4.下载mariadb数据库,服务端和客户端
yum install MariaDB-server MariaDB-client
# 或者
yum install MariaDB-server MariaDB-client -y
yum源就是配置在/etc/yum.repos.d/底下的*.repo文件而已
二:启动mariadb数据库
#启动MariaDB
systemctl start mariadb
# 启动以后 查看有没有mysql进程
ps -ef | grep mysql
# 查看mysql的网络信息
netstat -tunlp | grep 3306
[root@bogon yum.repos.d]# netstat -tunlp | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 86177/mysqld
mysql -uroot -p
通过客户端连接数据库
mysql有哪些种类的客户端?
mysql -uroot -p
pymysql
navicat(可视化工具)
启动mariadb相关命令
mariadb数据库的相关命令是:
systemctl start mariadb #启动MariaDB
systemctl stop mariadb #停止MariaDB
systemctl restart mariadb #重启MariaDB
systemctl enable mariadb #设置开机启动
三:初始化mysql
3.1:详解
在确认 MariaDB 数据库软件程序安装完毕并成功启动后请不要立即使用。为了确保数据 库的安全性和正常运转,需要先对数据库程序进行初始化操作。这个初始化操作涉及下面 5 个 步骤。
➢ 设置 root 管理员在数据库中的密码值(注意,该密码并非 root 管理员在系统中的密 码,这里的密码值默认应该为空,可直接按回车键)。
➢ 设置 root 管理员在数据库中的专有密码。
➢ 随后删除匿名账户,并使用 root 管理员从远程登录数据库,以确保数据库上运行的业
务的安全性。
➢ 删除默认的测试数据库,取消测试数据库的一系列访问权限。
➢ 刷新授权列表,让初始化的设定立即生效。
确保mariadb服务器启动后,执行命令初始化
mysql_secure_installation
3.2:配置信息
# 默认回车
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
# 设置密码 123
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
#移出匿名用户 yes
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
# 允许远程连接
Disallow root login remotely? [Y/n] n
... skipping.
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
# 删除测试数据库
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
# 立即刷新权限表
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
3.3:配置信息图片