<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MySQL &#8211; wqh博客</title>
	<atom:link href="https://wangqianhong.com/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>https://wangqianhong.com</link>
	<description>和而不同</description>
	<lastBuildDate>Thu, 26 Sep 2024 01:42:44 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://wangqianhong.com/wp-content/uploads/2020/09/cropped-1-1-1-32x32.png</url>
	<title>MySQL &#8211; wqh博客</title>
	<link>https://wangqianhong.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>在Centos上安装MySQL</title>
		<link>https://wangqianhong.com/2020/08/mysql/</link>
					<comments>https://wangqianhong.com/2020/08/mysql/#comments</comments>
		
		<dc:creator><![CDATA[wqh_work]]></dc:creator>
		<pubDate>Mon, 31 Aug 2020 00:18:28 +0000</pubDate>
				<category><![CDATA[技术文章]]></category>
		<category><![CDATA[Centos]]></category>
		<category><![CDATA[MySQL]]></category>
		<guid isPermaLink="false">https://localhost/?p=31</guid>

					<description><![CDATA[<p>文主要记录在Centos8下使用root账安装MySQL8 yum安装 如果centos自带了mys&#8230; <a href="https://wangqianhong.com/2020/08/mysql/" class="more-link read-more" rel="bookmark">继续阅读 <span class="screen-reader-text">在Centos上安装MySQL</span><i class="fa fa-arrow-right"></i></a></p>
<p><a rel="nofollow" href="https://wangqianhong.com/2020/08/mysql/">在Centos上安装MySQL</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>文主要记录在Centos8下使用root账安装MySQL8</p>



<h3>yum安装</h3>



<p>如果centos自带了mysql8，则可以使用yum命令安装，查看mysql8命令：</p>



<pre class="wp-block-preformatted"><code>yum list | grep mysql</code>
Failed to set locale, defaulting to C.UTF-8
mysql.x86_64             8.0.21-1.module_el8.2.0+493+63b41e36 appstream
mysql-common.x86_64      8.0.21-1.module_el8.2.0+493+63b41e36 appstream
mysql-errmsg.x86_64      8.0.21-1.module_el8.2.0+493+63b41e36 appstream
mysql-server.x86_64      8.0.21-1.module_el8.2.0+493+63b41e36 appstream</pre>



<p>安装mysql8命令：</p>



<pre class="wp-block-code"><code>yum -y install mysql mysql-server</code></pre>



<p>等待安装完成，直接启动即可。</p>



<p>如果centos不自带mysql8，则需要按下面的步骤下载解压。</p>



<h3>下载解压</h3>



<pre class="wp-block-code"><code>wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.21-1.el8.x86_64.rpm-bundle.tar</code></pre>



<pre class="wp-block-code"><code>tar -xvf mysql-8.0.21-1.el8.x86_64.rpm-bundle.tar</code></pre>



<p>解压完成，可以看到rpm包：</p>



<pre class="wp-block-verse">mysql-community-client-debuginfo-8.0.21-1.el8.x86_64.rpm<br>mysql-community-server-debug-8.0.21-1.el8.x86_64.rpm<br>mysql-community-debugsource-8.0.21-1.el8.x86_64.rpm<br>mysql-community-test-8.0.21-1.el8.x86_64.rpm<br>mysql-community-test-debuginfo-8.0.21-1.el8.x86_64.rpm<br>mysql-community-common-8.0.21-1.el8.x86_64.rpm<br>mysql-community-devel-8.0.21-1.el8.x86_64.rpm<br>mysql-community-libs-8.0.21-1.el8.x86_64.rpm<br>mysql-community-libs-debuginfo-8.0.21-1.el8.x86_64.rpm<br>mysql-community-server-debug-debuginfo-8.0.21-1.el8.x86_64.rpm<br>mysql-community-server-8.0.21-1.el8.x86_64.rpm<br>mysql-community-client-8.0.21-1.el8.x86_64.rpm<br>mysql-community-debuginfo-8.0.21-1.el8.x86_64.rpm<br>mysql-community-server-debuginfo-8.0.21-1.el8.x86_64.rpm</pre>



<h3>安装</h3>



<p>在进行下一步安装之前要先把依赖安装上</p>



<pre class="wp-block-code"><code>yum install openssl-devel numactl-devel libaio-devel perl-Getopt-Long net-tools</code></pre>



<p>然后依次安装rpm包</p>



<pre class="wp-block-code"><code>rpm -ivh mysql-community-common-8.0.21-1.el8.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.21-1.el8.x86_64.rpm
rpm -ivh mysql-community-client-8.0.21-1.el8.x86_64.rpm
rpm -ivh mysql-community-server-8.0.21-1.el8.x86_64.rpm</code></pre>



<p>到这里MySQL基本上就安装好了，不过为了以后开发的方便可以把mysql-devel也安装上</p>



<pre class="wp-block-code"><code>rpm -ivh mysql-community-devel-8.0.21-1.el8.x86_64.rpm</code></pre>



<h3>启动</h3>



<pre class="wp-block-code"><code>systemctl start mysqld</code></pre>



<p>设置开机启动</p>



<pre class="wp-block-code"><code>systemctl enable mysqld</code></pre>



<h3>修改root密码</h3>



<p>MySQL启动之后，如果是8.0以上版本，没有初始密码，直接用空密码就可以登录，如果需要初始密码，root的初始密码一般在/var/log/mysqld.log中，通过匹配temporary password可以定位到root的初始密码</p>



<pre class="wp-block-verse"> A temporary password is generated for root@localhost: _u=8-FsP/xqk</pre>



<p>复制root密码，就可以直接登录了</p>



<pre class="wp-block-code"><code>mysql -uroot -p</code></pre>



<p>登录成功后，我们可以用下面的命令修改root默认密码。MySQL为了安全要求使用字母数字符合的组合，如果新密码太简单会报错</p>



<pre class="wp-block-code"><code>alter user 'root'@'localhost' identified by '你的新密码';</code></pre>



<p>最后使用刷新命令，就可以使用新密码登录了</p>



<pre class="wp-block-code"><code>flush privileges;</code></pre>



<h3>基本操作</h3>



<p>创建一个数据库，使用utf8mb4字符集，方便存储表情等复杂字符：</p>



<pre class="wp-block-code"><code>create database if not exists 你的数据库名字 default charset utf8mb4 collate utf8mb4_0900_ai_ci;</code></pre>



<p>utf8mb4_0900_ai_ci 可以支持复杂中文字体的查询</p>



<p>创建一个普通账号，%表示可以远程登录，localhost表示只能本地登录：</p>



<pre class="wp-block-preformatted"><code>create user 'test'@'%' identified by '你的密码';</code>
<code>create user 'test'@'localhost' identified by '你的密码';</code></pre>



<p>为数据库授权账号：</p>



<pre class="wp-block-code"><code>grant all privileges on 你的数据库名字.* to 'test'@'%';</code></pre>



<p>也可以取消授权：</p>



<pre class="wp-block-code"><code>revoke all on 你的数据库名字.* from 'test'@'%';</code></pre>



<p>不要忘记刷新：</p>



<pre class="wp-block-code"><code>flush privileges;</code></pre>
<p><a rel="nofollow" href="https://wangqianhong.com/2020/08/mysql/">在Centos上安装MySQL</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://wangqianhong.com/2020/08/mysql/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
