Heim >Datenbank >MySQL-Tutorial >腾讯云CentOS7.0使用yum安装mysql_MySQL

腾讯云CentOS7.0使用yum安装mysql_MySQL

WBOY
WBOYOriginal
2016-05-27 13:46:341698Durchsuche

背景:

今天才申请了腾讯云+校园计划的1元服务器,(http://www.qcloud.com/event/qcloudSchool)安装了Centos7.0,在安装mysql的时候,使用yum list | grep mysql 来查找yum源中是否有mysql,结果如下:

<code class="hljs avrasm">[root@VM_47_56_centos ~]# yum list | grep mysql
akonadi-mysql.x86_64                    1.9.2-4.el7                    base     
apr-util-mysql.x86_64                   1.5.2-6.el7                    base       
mysql-proxy.x86_64                      0.8.5-2.el7                    epel     
mysql-proxy-devel.x86_64                0.8.5-2.el7                    epel     
mysql-router.x86_64                     2.0.2-1.el7                    mysql-tools-community
mysql-router-debuginfo.x86_64           2.0.2-1.el7                    mysql-tools-community
mysql-utilities.noarch                  1.5.6-1.el7                    mysql-tools-community
mysql-utilities-extra.noarch            1.5.6-1.el7                    mysql-tools
mysqlreport.noarch                      3.5-11.el7                     epel     
mysqltuner.noarch                       1.2.0-7.el7                    epel     
省略部分内容。。。。
[root@VM_47_56_centos ~]# </code>

总之是看不到mysql-server的影子,(PS:据说Centos7.0的源中暂时还没有mysql,但是相同版本的Centos在阿里云是可以直接使用yum install mysql-server 来直接安装mysql的)

于是找了一些mysql的安装源,安装过程如下:

安装过程:

为了解决这个问题,我们要先下载mysql的repo源。

1、下载mysql的repo源
<code class="hljs avrasm"><code class="hljs avrasm">$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm</code></code>
<code class="hljs avrasm">2、安装mysql-community-release-el7-5.noarch.rpm包
<code class="hljs avrasm"><code class="hljs avrasm"><code class="hljs lasso">$ sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm</code></code></code>

<code class="hljs avrasm"><code class="hljs lasso">安装这个包后,会获得两个mysql的yum repo源:<br> /etc/yum.repos.d/mysql-community.repo和<br> /etc/yum.repos.d/mysql-community-source.repo。

<code class="hljs avrasm"><code class="hljs lasso">3、安装mysql
<code class="hljs avrasm"><code class="hljs avrasm"><code class="hljs lasso"><code class="hljs bash">$ sudo yum install mysql-server</code></code></code></code>

<code class="hljs avrasm"><code class="hljs lasso"><code class="hljs bash">这个过程中就会看到有mysql的软件包存在:

<code class="hljs avrasm"><code class="hljs avrasm"><code class="hljs lasso"><code class="hljs bash"><code class="hljs asciidoc">[root@VM_47_56_centos ~]# sudo yum install mysql-server
已加载插件:fastestmirror, langpacks                   
| 2.5 kB  00:00:00     
mysql-tools-community                                                                  | 2.5 kB  00:00:00     
mysql56-community                                                                         | 2.5 kB  00:00:00     
(1/3): mysql-connectors-community/x86_64/primary_db                                       | 8.6 kB  00:00:00     
(2/3): mysql-tools-community/x86_64/primary_db                                            |  22 kB  00:00:00     
(3/3): mysql56-community/x86_64/primary_db                                                | 109 kB  00:00:01     
Loading mirror speeds from cached hostfile
 * base: mirrors.sina.cn
 * extras: mirrors.sina.cn
 * updates: mirrors.sina.cn
正在解决依赖关系
--> 正在检查事务

省略内容。。。

依赖关系解决
=================================================================================================================
 Package                           架构             版本                       源                           大小
=================================================================================================================
正在安装:
 mysql-community-libs              x86_64           5.6.27-2.el7               mysql56-community           2.0 M
      替换  mariadb-libs.x86_64 1:5.5.44-1.el7_1
 mysql-community-server            x86_64           5.6.27-2.el7               mysql56-community            58 M
为依赖而安装:
 mysql-community-client            x86_64           5.6.27-2.el7               mysql56-community            19 M
 mysql-community-common            x86_64           5.6.27-2.el7               mysql56-community           256 k
 numactl-libs                      x86_64           2.0.9-5.el7_1              

事务概要
=================================================================================================================
安装  2 软件包 (+9 依赖软件包)

总下载量:80 M
Is this ok [y/d/N]: y</code></code></code></code></code>

<code class="hljs avrasm"><code class="hljs lasso"><code class="hljs bash"><code class="hljs asciidoc">下边的安装和其他安装一样,

<code class="hljs avrasm"><code class="hljs lasso"><code class="hljs bash"><code class="hljs asciidoc">根据步骤安装就可以了,不过安装完成后,没有密码,需要重置密码。

<code class="hljs avrasm"><code class="hljs lasso"><code class="hljs bash"><code class="hljs asciidoc">4、重置密码

<code class="hljs avrasm"><code class="hljs lasso"><code class="hljs bash"><code class="hljs asciidoc">重置密码前,首先要登录

<code class="hljs avrasm"><code class="hljs avrasm"><code class="hljs lasso"><code class="hljs bash"><code class="hljs asciidoc"><code class="hljs ruby">$ mysql -u root</code></code></code></code></code></code>

<code class="hljs avrasm"><code class="hljs lasso"><code class="hljs bash"><code class="hljs asciidoc"><code class="hljs ruby">登录时有可能报这样的错:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2),原因是/var/lib/mysql的访问权限问题。下面的命令把/var/lib/mysql的拥有者改为当前用户:

<code class="hljs avrasm"><code class="hljs avrasm"><code class="hljs lasso"><code class="hljs bash"><code class="hljs asciidoc"><code class="hljs ruby"><code class="hljs bash">$ sudo chown -R mysql:mysql /var/lib/mysql #这里的mysql是用户名(需要设置用户组合用户)</code></code></code></code></code></code></code>

<code class="hljs avrasm"><code class="hljs lasso"><code class="hljs bash"><code class="hljs asciidoc"><code class="hljs ruby"><code class="hljs bash">然后,重启服务:

<code class="hljs avrasm"><code class="hljs avrasm"><code class="hljs lasso"><code class="hljs bash"><code class="hljs asciidoc"><code class="hljs ruby"><code class="hljs bash"><code class="hljs ruby">$ service mysqld restart</code></code></code></code></code></code></code></code>

<code class="hljs avrasm"><code class="hljs lasso"><code class="hljs bash"><code class="hljs asciidoc"><code class="hljs ruby"><code class="hljs bash"><code class="hljs ruby">接下来登录重置密码:

<code class="hljs avrasm"><code class="hljs avrasm"><code class="hljs lasso"><code class="hljs bash"><code class="hljs asciidoc"><code class="hljs ruby"><code class="hljs bash"><code class="hljs ruby"><code class="hljs php">$ mysql -u root
mysql > use mysql;
mysql > update user set password=password(&#39;xu827928&#39;) where user=&#39;root&#39;;
mysql > exit;</code></code></code></code></code></code></code></code></code>
<code class="hljs avrasm"><code class="hljs lasso"><code class="hljs bash"><code class="hljs asciidoc"><code class="hljs ruby"><code class="hljs bash"><code class="hljs ruby"><code class="hljs php">5、开放3306端口(可以不用设置)
<code class="hljs avrasm"><code class="hljs avrasm"><code class="hljs lasso"><code class="hljs bash"><code class="hljs asciidoc"><code class="hljs ruby"><code class="hljs bash"><code class="hljs ruby"><code class="hljs php"><code class="hljs bash">$ sudo vim /etc/sysconfig/iptables</code></code></code></code></code></code></code></code></code></code>

<code class="hljs avrasm"><code class="hljs lasso"><code class="hljs bash"><code class="hljs asciidoc"><code class="hljs ruby"><code class="hljs bash"><code class="hljs ruby"><code class="hljs php"><code class="hljs bash">添加以下内容:

<code class="hljs avrasm"><code class="hljs avrasm"><code class="hljs lasso"><code class="hljs bash"><code class="hljs asciidoc"><code class="hljs ruby"><code class="hljs bash"><code class="hljs ruby"><code class="hljs php"><code class="hljs bash"><code class="hljs lasso">-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT</code></code></code></code></code></code></code></code></code></code></code>

<code class="hljs avrasm"><code class="hljs lasso"><code class="hljs bash"><code class="hljs asciidoc"><code class="hljs ruby"><code class="hljs bash"><code class="hljs ruby"><code class="hljs php"><code class="hljs bash"><code class="hljs lasso">保存后重启防火墙:

<code class="hljs avrasm"><code class="hljs avrasm"><code class="hljs lasso"><code class="hljs bash"><code class="hljs asciidoc"><code class="hljs ruby"><code class="hljs bash"><code class="hljs ruby"><code class="hljs php"><code class="hljs bash"><code class="hljs lasso"><code class="hljs bash">$ sudo service iptables restart</code></code></code></code></code></code></code></code></code></code></code></code>

<code class="hljs avrasm"><code class="hljs lasso"><code class="hljs bash"><code class="hljs asciidoc"><code class="hljs ruby"><code class="hljs bash"><code class="hljs ruby"><code class="hljs php"><code class="hljs bash"><code class="hljs lasso"><code class="hljs bash">这样从其它客户机也可以连接上mysql服务了。

<code class="hljs avrasm"><code class="hljs lasso"><code class="hljs bash"><code class="hljs asciidoc"><code class="hljs ruby"><code class="hljs bash"><code class="hljs ruby"><code class="hljs php"><code class="hljs bash"><code class="hljs lasso"><code class="hljs bash">6、修改权限可以使其他机器登录:
<code class="hljs avrasm"><code class="hljs avrasm"><code class="hljs lasso"><code class="hljs bash"><code class="hljs asciidoc"><code class="hljs ruby"><code class="hljs bash"><code class="hljs ruby"><code class="hljs php"><code class="hljs bash"><code class="hljs lasso"><code class="hljs bash"><code class="hljs lasso">?mysql>mysql -h localhost -u root  //这样应该可以进入MySQL服务器 
mysql>GRANT ALL PRIVILEGES ON *.* TO &#39;root&#39;@&#39;%&#39; WITH GRANT OPTION  //赋予任何主机访问数据的权限 
mysql>FLUSH PRIVILEGES //修改生效 
mysql>EXIT //退出MySQL服务器</code></code></code></code></code></code></code></code></code></code></code></code></code>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:mysql日志学习总结_MySQLNächster Artikel:MySQL复合分区_MySQL