登录
首页 >  数据库 >  MySQL

2018年第四周-在centos7安装mysql6

来源:SegmentFault

时间:2023-01-16 16:54:12 286浏览 收藏

大家好,今天本人给大家带来文章《2018年第四周-在centos7安装mysql6》,文中内容主要涉及到MySQL,如果你对数据库方面的知识点感兴趣,那就请各位朋友继续看下去吧~希望能真正帮到你们,谢谢!

“Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program.”- Linus Torvalds

yum安装mysql

从yum安装,参考https://dev.mysql.com/doc/mys...

1.先添加mysql的yum库下载mysql57-community-release-el7-11.noarch.rpm,地址https://dev.mysql.com/downloa...
2.安装mysql的yum库

 sudo rpm -Uvh mysql57-community-release-el7-11.noarch.rpm

3.查看mysql的yun库

yum repolist all | grep mysql

4.启动mysql6

shell> sudo yum-config-manager --disable mysql57-community
shell> sudo yum-config-manager --enable mysql56-community

如果提示yum-config-manager命令不存在,则可以直接修改文件/etc/yum.repos.d/mysql-community.repo,把mysql56-community的enabled置为1,mysql57-community的enabled置为0

vim mysql-community.repo
#启动使用MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

5.安装mysql

sudo yum install mysql-community-server

6.启动mysql

sudo service mysqld start

7.初始化mysql(可以设置root密码等)

mysql_secure_installation

8.登录mysql

mysql -uroot -p

mysql常用命令(用root用户登录)

查看数据库有哪些用户

SELECT User, Host, Password FROM mysql.user;

创建一个数据库名为"mydb_name"

create database mydb_name default character set utf8;

创建用户"jevoncode",任意域名都能登录,密码为jevoncodepassword

create user 'jevoncode'@'%' identified by 'jevoncodepassword';

授权mydb_name数据的所有权限给jevoncode用户

grant all privileges on mydb_name.*  to 'jevoncode'@'%';

刷新数据库权限

flush privileges;

查看用户的权限

show grants for jevoncode@'%';

常见问题

查看3306端口是否监听,执行命令后没有返回消息,则没有监听此端口

netstat -tunpl |grep 3306

查看防火墙是否允许访问,执行命令后没有返回消息能用则表明不能方位该端口

iptables -L -n|grep 3306

设置防火墙允许访问端口3306

iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

保存防火墙策略

iptables-save > iptables.rules

中文乱码时,用这命令SHOW VARIABLES LIKE 'char%';查看mysql-server的编码

mysql> SHOW VARIABLES LIKE 'char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

mysql默认server编码为latin1,所以设置为utf8,修改/etc/my.cnf,在[mysqld]下添加:

[mysqld]
character-set-server=utf8

本篇关于《2018年第四周-在centos7安装mysql6》的介绍就到此结束啦,但是学无止境,想要了解学习更多关于数据库的相关知识,请关注golang学习网公众号!

声明:本文转载于:SegmentFault 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>
评论列表