事尔 發表於 2022-12-31 20:59:00

centos安装mariadb

<p>新手,以前完全没玩过,走了很多弯路,感觉有必要做个笔记备忘</p>
<p>开发互联网项目首先想到的数据库一般就会是mysql,以及他的衍生数据库,包括很多有经验的朋友也会给你推荐使用mysql</p>
<p>(以下内容中部分图片来自网友提供,感谢无私奉献的朋友们!)</p>
<p><span style="color: rgba(255, 0, 0, 1)">坑一:CentOS 7不能再用开源的MySql了,应该安装Mariadb</span></p>
<p>解决办法:</p>
<p>一顿操作猛如虎,发现我是250,买了个华为云服务器(CentOS 7),直接下载mysql包,解压,安装,按照网上的帖子一步步操作,直到最后卸载了mysql,<span style="color: rgba(255, 0, 0, 1)">因为CentOS 7上不能再安装开源的mysql了(也就是不能用免费的了o(* ̄︶ ̄*)o),你想要的可能是安装mariadb!</span></p>
<p><strong>【mariadb安装步骤】:</strong></p>
<p><span style="font-size: 16px"><strong>1、准备工作</strong></span></p>
<p><strong>1.1、确保你的linux服务器外网是通的,方法很简单,ping www.baidu.com</strong></p>
<p><img src="https://img2023.cnblogs.com/blog/1238737/202212/1238737-20221231204734936-89684199.png"></p>
<p><strong>1.2、查看已安装的包</strong></p>
<p>&nbsp;命令:</p>
<div class="cnblogs_code">
<pre>rpm -qa | grep mysql</pre>
</div>
<p><img src="https://img2023.cnblogs.com/blog/1238737/202212/1238737-20221231204751811-486547841.png"></p>
<p><strong>1.3、如果存在已安装,逐个卸载掉这些包</strong></p>
<p>命令:</p>
<div class="cnblogs_code">
<pre>rpm -e --nodeps mariadb-xxxx。。。。</pre>
</div>
<p>全部卸载完后执行1.2的命令确认卸载干净。</p>
<p><span style="font-size: 16px"><strong>2、安装mariadb</strong></span></p>
<p><strong>2.1、安装</strong></p>
<p>命令:yum install mariadb-server</p>
<p><strong>2.2、 如果下载不成功,清理安装文件</strong></p>
<p>命令:yum clean all</p>
<p><strong>2.3、 确认下载安装</strong></p>
<p><strong><img src="https://img2023.cnblogs.com/blog/1238737/202212/1238737-20221231204958177-984857101.png"></strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>&nbsp;2.4、安装完成</strong></p>
<p><img src="https://img2023.cnblogs.com/blog/1238737/202212/1238737-20221231205014166-2017974752.png"></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;此时执行</p>
<div class="cnblogs_code">
<pre>rpm -qa | grep mariadb</pre>
</div>
<p>可以查看安装的内容!</p>
<p><span style="font-size: 16px"><strong>3、 数据库常用命令</strong></span><br>      命令:</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">. 启动命令 systemctl start mariadb
</span><span style="color: rgba(128, 0, 128, 1)">2</span><span style="color: rgba(0, 0, 0, 1)">. 重启命令 systemctl restart mariadb
</span><span style="color: rgba(128, 0, 128, 1)">3</span><span style="color: rgba(0, 0, 0, 1)">. 关闭命令 systemctl stop mariadb
</span><span style="color: rgba(128, 0, 128, 1)">4</span><span style="color: rgba(0, 0, 0, 1)">. 开机自起 systemctl enable mariadb
</span><span style="color: rgba(128, 0, 128, 1)">5</span>. 关闭自起 systemctl disable mariadb</pre>
</div>
<p><span style="font-size: 16px"><strong>4、初始化数据库</strong></span></p>
<p><strong>4.1、执行命令:mysql_secure_installation</strong></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; 提示输入root用户密码,<span style="color: rgba(255, 0, 0, 1)">安装后初次进入,密码为空,直接回车就可以了 !</span></p>
<p><img src="https://img2023.cnblogs.com/blog/1238737/202212/1238737-20221231205241032-198408961.png"></p>
<p>&nbsp;</p>
<p><strong>4.2、设置root用户密码</strong></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;然后弹出是否设置root用户密码,输入y,然后回车</p>
<p><img src="https://img2023.cnblogs.com/blog/1238737/202212/1238737-20221231205320644-1601046800.png"></p>
<p>输入新密码,回车后在重复输入确认密码,回车完成密码设置,然后弹出是否删除匿名用户,输入y,回车完成匿名用户删除</p>
<p><strong>4.3、删除匿名用户</strong></p>
<p><strong><img src="https://img2023.cnblogs.com/blog/1238737/202212/1238737-20221231205347174-1272171.png"></strong></p>
<p>&nbsp;</p>
<p><strong>&nbsp;&nbsp;4.4、允许root远程登录</strong></p>
<div>&nbsp;<img src="https://img2023.cnblogs.com/blog/1238737/202212/1238737-20221231205404122-226284090.png">
<p>输入y,回车,允许root远程登录,然后选择是否删除test测试库</p>
<p><strong>4.5、删除test测试库</strong></p>
<p><strong><img src="https://img2023.cnblogs.com/blog/1238737/202212/1238737-20221231205425880-519275004.png"></strong></p>
<p>&nbsp;</p>
<p>&nbsp;输入y,回车,删除test库,然后选择是否新加载权限</p>
<p><strong>&nbsp;4.6、重新加载权限</strong></p>
<p><strong><img src="https://img2023.cnblogs.com/blog/1238737/202212/1238737-20221231205453487-1793424171.png"></strong></p>
<p>输入y,回车,安装完成!</p>
<p><span style="color: rgba(255, 0, 0, 1)">坑二</span>、数据库远程连接需要的两个配置(数据库允许用户远程访问、防护墙上要将数据库端口3306设置成ACCEPT)</p>
<p>解决办法:</p>
<p><span style="font-size: 16px"><strong>一、解决用户远程登录</strong></span></p>
<p><strong>(一)、执行命令:mysql -u root -p</strong><br>提示输入root用户密码,输入后回车,成功登录Mariadb,</p>
<p><strong>(二)、执行命令:GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的root密码' WITH GRANT OPTION;</strong></p>
<p><span style="font-size: 16px"><strong>二、解决防火墙问题</strong></span></p>
<p>1、关闭防火墙&nbsp; 2、增加白名单</p>
<p><strong><span style="font-size: 16px">三、添加用户及授权&nbsp;</span></strong></p>
<div>
<div>
<h3>创建用户</h3>
</div>
<div>命令:**CREATE USER 'username'@'host' IDENTIFIED BY 'password'; **<br>
说明:<br>
username - 你将创建的用户名,<br>
host - 指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost, 如果想让该用户可以从任意远程主机登陆,可以使用通配符%.<br>
password - 该用户的登陆密码,密码可以为空,如果为空则该用户可以不需要密码登陆服务器.<br>
例子:</div>
<div class="cnblogs_code">
<pre>CREATE USER <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">m23100</span><span style="color: rgba(128, 0, 0, 1)">'</span>@<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">localhost</span><span style="color: rgba(128, 0, 0, 1)">'</span> IDENTIFIED BY <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">123456</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">;
CREATE USER </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">m23100</span><span style="color: rgba(128, 0, 0, 1)">'</span>@<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">192.168.1.101</span><span style="color: rgba(128, 0, 0, 1)">'</span> IDENDIFIED BY <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">123456</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">;
CREATE USER </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">m23100</span><span style="color: rgba(128, 0, 0, 1)">'</span>@<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">%</span><span style="color: rgba(128, 0, 0, 1)">'</span> IDENTIFIED BY <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">123456</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">;
CREATE USER </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">m23100</span><span style="color: rgba(128, 0, 0, 1)">'</span>@<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">%</span><span style="color: rgba(128, 0, 0, 1)">'</span> IDENTIFIED BY <span style="color: rgba(128, 0, 0, 1)">''</span><span style="color: rgba(0, 0, 0, 1)">;
CREATE USER </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">m23100</span><span style="color: rgba(128, 0, 0, 1)">'</span>@<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">%</span><span style="color: rgba(128, 0, 0, 1)">'</span>;</pre>
</div>
<h3>授权:</h3>
<div>
<div>命令:**CREATE USER 'username'@'host' IDENTIFIED BY 'password'; **<br>
说明:<br>
username - 你将创建的用户名,<br>
host - 指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost, 如果想让该用户可以从任意远程主机登陆,可以使用通配符%.<br>
password - 该用户的登陆密码,密码可以为空,如果为空则该用户可以不需要密码登陆服务器.<br>
例子:</div>
<div class="cnblogs_code">
<div>
<div>GRANT SELECT, INSERT ON test.user TO 'm23100'@'%';<br>
GRANT ALL ON *.* TO 'm23100'@'%';<br>
flush privileges;刷新权限:</div>
</div>
</div>
<p>注意:用以上命令授权的用户不能给其它用户授权,如果想让该用户可以授权,用以下命令:</p>
<div class="cnblogs_code">
<pre>GRANT privileges ON databasename.tablename TO <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">username</span><span style="color: rgba(128, 0, 0, 1)">'</span>@<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">host</span><span style="color: rgba(128, 0, 0, 1)">'</span> WITH GRANT OPTION;</pre>
</div>
<p>&nbsp;</p>
</div>
</div>
<p>&nbsp;</p>
<p>版权声明:本文为CSDN博主「托塔雨天王」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。<br>参考地址:https://blog.csdn.net/xueren_83/article/details/124325803&nbsp; &nbsp;https://www.jianshu.com/p/4466e0cd0bd1</p>

</div><br><br>
来源:https://www.cnblogs.com/abel-he/p/17017261.html
頁: [1]
查看完整版本: centos安装mariadb