huangliang00 2020-02-12
自从 CentOS 7 开始,自带的数据库就变成 MariaDB 了,yum 安装之后的默认版本是 5.5
添加并编辑文件
添加MariaDB源
vi /etc/yum.repos.d/MariaDB.repo
粘贴官方的或者阿里云的镜像:
[mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.3/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
[mariadb] name = MariaDB baseurl = https://mirrors.aliyun.com/mariadb/yum/10.4/centos7-amd64/ gpgkey=https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB gpgcheck=1
yum install mariadb mariadb-server
启动数据库
systemctl start mariadb.service
第一次安装,没有密码,直接进入数据库
mysql -u root
设置初始密码
mysql_secure_installation
[root]$ /usr/bin/mysql_secure_installation #输入root(mysql)的密码。默认没有,直接回车 Enter current password for root (enter for none): #是否切换到unix套接字身份验证[Y/n] Switch to unix_socket authentication [Y/n] n #是否设置root密码 Change the root password? [Y/n] #如果选Y,就输入2次密码 New password: Re-enter new password: #是否删除匿名用户?(就是空用户),建议删除 Remove anonymous users? [Y/n] #是否不允许远程root登录 Disallow root login remotely? [Y/n] n #是否删除test数据库 Remove test database and access to it? [Y/n] n #是否加载权限使之生效 Reload privilege tables now? [Y/n] y
停止systemctl stop mariadb.service 重启 systemctl restart mariadb.service开机自启 systemctl enable mariadb.service
参考:https://blog.csdn.net/qq_34691713/article/details/83896662