mysql安装(centos7) 2019-03-09 - Go语言中文社区

mysql安装(centos7) 2019-03-09


1.卸载Mariadb

查询所安装的MariaDB组件:

[root@localhost logs]# rpm -qa | grep Maria*

    MariaDB-server-5.5.49-1.el7.centos.x86_64

    MariaDB-common-5.5.49-1.el7.centos.x86_64

    MariaDB-client-5.5.49-1.el7.centos.x86_64

卸载数据库:

[root@localhost logs]# yum -y remove maria*

删除数据库文件:(如果存在则删除,不存在就算了)

[root@localhost logs]# rm -rf /var/lib/mysql/*

[root@localhost logs]# rm -f /etc/my.cnf

[root@localhost logs]# rm -rf /var/lib/mysql/

2.安装mysql

mysql-devel可以用yum源安装:

[root@localhost logs]#yum install mysql-devel

mysql-server和mysql-client不能用yum源,yum源只有MariaDB:

[root@localhost logs]# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

[root@localhost logs]# rpm -ivh mysql-community-release-el7-5.noarch.rpm

[root@localhost logs]# yum install mysql-community-server

安装成功后重启mysql服务。

[root@localhost logs]# service mysqld restart

或者:

[root@localhost logs]# systemctl restart mysqld.service

初次安装mysql,root账户没有密码。

[root@yl-web yl]# mysql -u root

Welcome to the MySQL monitor.  Commands end with ; or g.

Your MySQL connection id is 3

Server version: 5.6.26 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql> show databases;

+--------------------+

| Database          |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test              |

+--------------------+

rows in set (0.01 sec)

mysql>

设置密码

mysql> set password for 'root'@'localhost' = password('root');

Query OK, 0 rows affected (0.00 sec)

mysql>

不需要重启数据库即可生效。

在mysql安装过程中如下内容:

Installed:

mysql-community-client.x86_64 0:5.6.26-2.el7                mysql-community-devel.x86_64 0:5.6.26-2.el7

mysql-community-libs.x86_64 0:5.6.26-2.el7                  mysql-community-server.x86_64 0:5.6.26-2.el7

Dependency Installed:

mysql-community-common.x86_64 0:5.6.26-2.el7

Replaced:

mariadb.x86_64 1:5.5.41-2.el7_0          mariadb-devel.x86_64 1:5.5.41-2.el7_0   mariadb-libs.x86_64 1:5.5.41-2.el7_0

mariadb-server.x86_64 1:5.5.41-2.el7_0

所以安装完以后mariadb自动就被替换了,将不再生效。

[root@yl-web yl]# rpm -qa |grep mariadb

[root@yl-web yl]#

三、配置mysql

1、编码

mysql配置文件为/etc/my.cnf

最后加上编码配置

[mysql]

default-character-set =utf8

这里的字符编码必须和/usr/share/mysql/charsets/Index.xml中一致。

2、远程连接设置

把在所有数据库的所有表的所有权限赋值给位于所有IP地址的root用户。

mysql> grant all privileges on *.* to root@'%' identified by 'root';

如果是新用户而不是root,则要先新建用户

mysql>create user 'username'@'%' identified by 'password';


3.如果是阿里云,需要开启安全组开放3306端口的外网访问权限;并关闭防火墙,命令见《centos7 防火墙》

此时就可以进行远程连接了。

4.如果运行爬虫,会报too many connection错误,作以下设置:(详情见《解决Mysql错误Too many connections的方法》)

vim /etc/my.conf

在[mysqld]下添加:

max_connections=1000

wait_timeout=100

interactive_timeout=100

max_allowed_packet=15M 

show processlist;

show variables like "max_connections"; 

show global variables like 'wait_timeout';

---------------------------

版权声明:本文来源简书,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://www.jianshu.com/p/212dd1437d4a
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-01-12 13:33:30
  • 阅读 ( 941 )
  • 分类:数据库

0 条评论

请先 登录 后评论

官方社群

GO教程

推荐文章

猜你喜欢