美文网首页
CentOS7搭建Mysql数据库以及配置

CentOS7搭建Mysql数据库以及配置

作者: 永远的逆光 | 来源:发表于2020-05-31 22:09 被阅读0次

1 查看系统环境

[root@VM_0_6_centos ~]# cat /etc/redhat-release

CentOS Linux release 7.6.1810 (Core)


2 Mysql安装

首先安装mysql和mysql-devel

yum install mysql

yum install mysql-devel

tips:由于CentOS 7 版本将MySQL数据库软件从默认的程序列表中移除,用mariadb代替了。MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。

注意:在CentOS7系统输入下列安装mysql-server会发生错误

CentOS7无法安装mysql-server

可以选择安装mariadb,但是由于习惯博主还是选择去官网安装下载安装mysql-server

wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-server

tips:使用第一条wget命令可能会出现Unable to establish SSL connection的错误提示,解决办法是在wget命令末尾加上-- --no-check-certificate这是因为wget在使用HTTPS协议时,默认会去验证网站的证书,而这个证书验证经常会失败。加上"--no-check-certificate"选项,就能排除掉这个错误。

安装成功后重启mysql服务。
#service mysqld restart

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

[root@VM_0_6_centos src]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.48 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, 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 respectiveowners.

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> set password for 'root'@'localhost' =password('password');
Query OK, 0 rows affected (0.00 sec)

mysql>

3 配置Mysql

1)编码

在使用mysql数据库的过程中,将中文数据插入到数据库的时候会出现数据乱码的问题。这主要是由于数据库的编码不支持中文的编码,因此在数据库在显示中文字符的情况下会出现令人不知所措的字符。
mysql的默认编码是Latin1,不支持中文字符的显示,所以最好将mysql的默认编码改为utf-8。
可以先查看mysql数据库的编码,进入mysql数据库,输入show variables like "char%"

character_set_database值为latin1

如果character_set_database值为utf-8则无需进行下列操作

mysql配置文件为/etc/my.cnf
最后加上编码配置

[mysql]
default-character-set =utf8

2)远程连接Mysql

很多情况下我们是在其他地方使用数据库,这时候我们应该把在所有数据库的所有表的所有权限赋值给位于所有IP地址的root用户。

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

相关文章

网友评论

      本文标题:CentOS7搭建Mysql数据库以及配置

      本文链接:https://www.haomeiwen.com/subject/dgtqzhtx.html