配置妥当yum库就可以安装MariaDB数据库的主程序和服务端程序了。
1.安装:yum install mariadb mariadb-server
2.启动 : systemctl start mariadb (启动后先不要立即使用,要先对数据库程序进行初始)
3.初始化操作:mysql_secure_install
Enter current password for root (enter for none): 当前数据库密码为空,直接回车
Set root password? [Y/n]:y 输入为root管理员设置的数据库密码,然后再次确认密码
Remove anonymous users? [Y/n]:y 删除匿名用户
Disallow root login remotely? [Y/n]:y 禁止root管理员从远程登录
Remove test database and access to it? [Y/n]:y 删除test数据库并取消对它的访问权限
Reload privilege tables now? [Y/n]:y 刷新授权表,让初始化的设定立即生效
(4).在很多生产环境中需要使网站和数据库分离,如果需要让root管理员远程访问数据库,可在3.步的初始化中设置策略允许root管理员远程访问数据库。然后设置防火墙,使它放行对数据库服务程序(mysql)的访问请求:#firewall-cmd --permanent --add-service mysql
#firewall-cmd --reload
我遇到的问题:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
这个错误是由密码错误引起的,可以重置密码:
1.重置密码的第一步就是跳过MySQL的密码认证过程
#vim /etc/my.cn
在[mysqld]文本段下任意一行添加“skip-grant-tables”用来跳过密码验证的过程
2.重启MySQL
3.进入mysql,重置密码,刷新授权表
#mysql
#update user set password=password("你的新密码") where user="root";
#flush privileges;
4.将/etc/my.cnf文档中添加的内容去掉