当前位置:网站首页>CentOS安装mysql数据库
CentOS安装mysql数据库
2022-07-22 10:28:00 【奔腾游子】
CentOS安装mysql数据库
- 如果没有安装wget,先安装
yum -y install wget
- 下载MySQL官方的 Yum Repository
wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm
- 使用上边的命令我们就下载到了 Yum Repository,之后我们就可以使用 yum 来进行安装了。
yum -y install mysql57-community-release-el7-10.noarch.rpm
- 安装mysql服务端
yum -y install mysql-community-server
- 启动mysql
systemctl start mysqld.service
- 查看mysql运行状态
systemctl status mysqld.service
- 此时,我们的数据库已经运行起来了,不过我们要进入我们的数据库的话还需要在日志中找到我们的 root 用户的密码。在新的版本中,默认生成了 root 用户密码。
grep "passsword" /var/log/mysqld.log
通过上边的命令我们可以查看到我们的 root 用户的密码。
mysql -uroot -p #输入密码进入数据库。
输入初始密码,此时不能做任何事情,因为MySQL默认必须修改密码之后才能操作数据库:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
这里密码要有一定的复杂度。要包括数字,大写字母、小写字母、特殊字符。
修改完密码之后我们就可以进行正常的操作了。
但是如果想设置简答的密码,可以进行如下设置:
首先,修改validate_password_policy参数的值
set global validate_password_policy=0;
再修改密码的长度
set global validate_password_length=1;
再次执行修改密码就可以了
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
- 设置开机启动的两条命令
systemctl enable mysqld
systemctl daemon-reload
- 添加远程登录用户
默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接,或者添加一个允许远程连接的帐户,为了安全起见,我添加一个新的帐户:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
语法解析:grant all privileges on 库名.表名 to 用户名@"%" identified by “密码”;
数据库名.表名 如果写成*.*代表授权所有的数据库
flush privileges; # 刷新刚才的内容
- 配置默认编码为utf8
改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
- 重新启动mysql服务
systemctl restart mysqld
边栏推荐
- Elastic Search 学习入门之restful的高级查询操作(九)
- All subsets of nc27 set (I)
- pyplot. When using plot: userwarning: starting a Matplotlib GUI outside of the main thread will like fail
- [database basic dry goods] MySQL foundation and slow query optimization practice
- Websites jump inexplicably. What is website hijacking from Baidu? How to solve Baidu snapshot hijacking
- iptables实现负载均衡
- Leetcode 300. longest increasing subsequence
- Kotlin learning II: classes and objects
- 数据库使用QueryRunner模拟封装
- 【C】二叉树遍历的递归与非递归写法
猜你喜欢
Fluent 2 Advanced (IV): Based on navigator 2.0 packaging
蓝桥杯省赛训练营——常用STL
Elastic Search 学习入门之ES的简单操作命令(二)
What are the common ways for websites to be hacked and hijacked? What are the DNS hijacking tools?
Host Ping fails in VMware NAT mode virtual machine: different from most methods
网站安全之域名被劫持、域名被劫持后该怎么办!!!
ZCU102板上PS端的E2PROM读写(XIICPS)
appstore 上传屏幕快照尺寸
What are the ways for Baidu homepage to be hijacked by TN? There are two ways to solve Baidu hijacking
HDU5667 Sequence
随机推荐
Altium一键自动出BOM
pyplot. When using plot: userwarning: starting a Matplotlib GUI outside of the main thread will like fail
Promise usage
Flutter 2进阶(三):模仿哔哩哔哩登录注册
蓝桥杯省赛训练营——日期的计算
Elastic Search 学习入门之生产环境下node.master和node.data的设置(三)
How to deal with DNS hijacked? Five ways to deal with it
NC4 judge whether there is a ring in the linked list
oc 项目倒入swift 代码注意事项
Fluent 2 Advanced (VIII): eventbus, carousel map and immersive status bar
生成删除数据库所有表的外检脚本
If else optimization
How to clear localstorage data after closing the browser
Precautions for pouring swift code into OC project
数据开发常用工具---查询结果邮件定时发送
美国土安全局对特勤局删除的国会大厦骚乱期间电子通信记录展开调查
Nc54 sum of three numbers
ping: www.baidu. Com: unknown name or service reason analysis
【C】二叉树遍历的递归与非递归写法
求幂的位数,求阶乘的位数