contos7 mysql库_centos7 mysql数据库安装和配置

本文详细介绍了在CentOS7上安装MariaDB和MySQL数据库的两种方法,包括设置root用户密码、远程连接配置以及my.cnf编码配置。在安装过程中,MariaDB可能会自动替换原有的MySQL,并提供了相关命令行操作来验证安装和配置。
摘要由CSDN通过智能技术生成

)

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 2

Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> show databases;

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

| Database                    |

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

| information_schema   |

| mysql                   |

| performance_schema |

| test                            |

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

4 rows in set (0.00 sec)

设置密码

MariaDB [(none)]> set password for ‘root‘@‘localhost‘ =password(‘redhat‘);

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]>

安装mariadb后显示的也是 MariaDB [(none)]> ,可能看起来有点不习惯。下面是第二种方法。

2、方法二:官网下载安装mysql-server

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

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

Preparing... ################################# [100%]

Updating / installing...

1:mysql-community-release-el7-5 ################################# [100%]

[root@mysql ~]# ll /etc/yum.repos.d/

total 48

-rw-r--r-- 1 root root 1664 Sep 5 09:05 CentOS-Base.repo

-rw-r--r-- 1 root root 1309 Sep 5 09:05 CentOS-CR.repo

-rw-r--r-- 1 root root 649 Sep 5 09:05 CentOS-Debuginfo.repo

-rw-r--r-- 1 root root 314 Sep 5 09:05 CentOS-fasttrack.repo

-rw-r--r-- 1 root root 630 Sep 5 09:05 CentOS-Media.repo

-rw-r--r-- 1 root root 1331 Sep 5 09:05 CentOS-Sources.repo

-rw-r--r-- 1 root root 6639 Sep 5 09:05 CentOS-Vault.repo

-rw-r--r-- 1 root root 951 Oct 2 2017 epel.repo

-rw-r--r-- 1 root root 1050 Oct 2 2017 epel-testing.repo

-rw-r--r-- 1 root root 1209 Jan 29 2014 mysql-community.repo

-rw-r--r-- 1 root root 1060 Jan 29 2014 mysql-community-source.repo

[root@mysql ~]# yum install mysql-community-server

安装成功后重启mysql服务。

[root@mysql ~]# service mysqld restart

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

[root@mysql ~]# mysql -u root

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

Your MySQL connection id is 2

Server version: 5.6.45 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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 |

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

3 rows in set (0.00 sec)

mysql>

设置密码

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

Query OK, 0 rows affected (0.00 sec)

mysql>

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

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

653b758dad086020095f3bb32630efc6.png

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

[root@mysql ~]# rpm -qa |grep mariadb

[root@mysql ~]#

三、配置mysql

1、编码

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

最后加上编码配置

[root@mysql ~]# vim /etc/my.cnf

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

symbolic-links=0

[mysqld_safe]

log-error=/var/log/mariadb/mariadb.log

pid-file=/var/run/mariadb/mariadb.pid

[mysql]

default-character-set =utf8

!includedir /etc/my.cnf.d

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

[root@mysql ~]# vim /usr/share/mysql/charsets/Index.xml

0892c90aa1e4c3506bc812962902e673.png

2、远程连接设置

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

[root@mysql ~]# mysql -uroot -p

Enter password:     (密码是:redhat)

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 6

Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> grant all privileges on *.* to root@‘%‘identified by ‘redhat‘;

Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]>

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

MariaDB [(none)]> create user ‘admin‘@‘%‘ identified by ‘Xuanbao123456‘;

Query OK, 0 rows affected (0.00 sec)

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

[root@c1 ~]# mysql -uadmin -p -h192.168.122.20

Enter password:     (密码是:Xuanbao123456)

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 7

Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]>

centos7 mysql数据库安装和配置

标签:令行   启动   redhat   reserve   data   log-error   ide   red   char

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉

本文系统来源:https://www.cnblogs.com/xuanbao/p/11627824.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值