Centos-Install-MYSQL
Centos7-Install-MYSQL
-
环境检测
1
2
3
4
5
6
7# 检测是否存在 mysql
rpm -qa | grep mysql
# 检测是否存在 mariadb
rpm -qa grep mariadb
# 存在删除
rpm -e --nodeps 存在版本 -
下载
-
下载地址
下载社区版本 选择社区版服务 选择适合系统版本 进入下载页 获取下载链接
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23# 接下来我们在 Centos7 系统下使用 yum 命令安装 MySQL,需要注意的是 CentOS 7 版本中 MySQL
数据库已从默认的程序列表中移除,所以在安装前我们需要先去官网下载 Yum 资源包,下载地址为:https://dev.mysql.com/downloads/repo/yum/
# http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm => 5
# https://dev.mysql.com/get/mysql80-community-release-el7-6.noarch.rpm => 8
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
# 安装 mysql 仓库
rpm -ivh mysql-community-release-el7-5.noarch.rpm
# 验证安全性(可以忽略) 和 网站提供的比较 一致则是安全的包
md5sum mysql-community-release-el7-5.noarch.rpm
# 查看仓库
ls /etc/yum.repos.d
# 更新仓库
yum makecache
# 查看仓库
yum repolist
# 更新
yum update
# 安装 mysql 服务(yum 可以解决依赖问题)
yum list | grep mysql-com
yum -y install mysql-server | yum -y install mysql-community-server.x86_64
# 安装后位置固定
cd /var/lib/mysql安装 server -
-
权限设置
1
2
3
4
5# 添加用户组
groupadd mysql
useradd -r -g mysql mysql
# 添加权限
chown -R mysql:mysql /var/lib/mysql/ -
初始化
mysql
1
mysqld --initialize
-
启动
mysql
1
systemctl start mysqld
-
查看运行状态
1
systemctl status mysqld
-
验证
1
mysqladmin --version
-
linux
上该命令将输出以下结果,该结果基于你的系统信息 版本检测 -
登录服务器
1
2# 可以直接登录
(如果未进入: grep 'password' /var/log/mysqld.log 获取临时密码 )
[root@localhost]# mysql登录连接 -
设置密码
1
[root@host]# mysqladmin -u root password "new_password";
添加密码与登录 -
查看字符集
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15# 查看 MySQL 配置文件信息 cd /usr/share/mysql
cat /etc/my.cnf
# 复制该配置文件
cp /etc/my.cnf my-cp.cnf
show variables like '%char%';
#编辑my.cnf 配置文件
vim /etc/my.cnf
[client] //如果没有 [client] 段,就自己添加上去
default-character-set=utf8
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci字符集查看 (创建时指定数据库字符集) -
开放远程连接
1
2
3use mysql;
update user set user.Host='%' where user.User='root';
flush privileges; -
安装目录问题
1
2
3
4
5
6
7usr/bin/mysql 是指:mysql
的运行路径
var/lib/mysql 是指:mysql数据库文件的存放路径
usr/lib/mysql 是指:mysql的安装路径
whereis mysql -
开机启动
1
ststemctl enable mysqld
-
忘记密码解决方案
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18vim /etc/my.cnf
[mysqld]
# 跳过权限表
skip-grant-tables
# 重启 mysql 服务
service mysqld restart
# 直接登录
mysql
# 查看字段 authentication_string => desc mysql.user;
# 设置新密码
update mysql.user set authentication_string=password('new_password') where user='root';
# 刷新
flush privileges;
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 coder-itl!
评论