Linux(centos7.X)中安装MySQL数据库

1、新建用户信息

# 新建用户组
groupadd fordream

# 新增用户  -g 指定用户组  -G指定附加组(这里不指定,本人不想给他太大权限,root就是root)  -d 指定家目录
useradd -g fordream -d /home/mysql mysql

# 设置用户密码
passwd mysql

2、下载资源

​ 进入到/usr/local/目录下,复制数据库资源进行wget,或者登陆数据资源网站选择适合的版本。

# 打开目录
cd /usr/local/

# 下载资源
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

3、安装

​ 在安装过程必须使用root权限,否则无法在/usr/local/下面修改配置信息等操作。

3.1 解压

# 解压压缩文件
tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
# 将解压后的目录改为mysql,纯粹是为了看着简洁和配置的时候方便
mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql
# 进入mysql目录
cd mysql
# 创建数据文件夹
mkdir data
# 修改拥有者权限(用户:用户组)
chown -R mysql:fordream /usr/local/mysql

3.2 初始化数据库

# 初始化命令
[root@localhost mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
# 初始化日志
2020-10-19T09:44:27.922810Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-10-19T09:44:29.465247Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-10-19T09:44:29.728870Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-10-19T09:44:29.796234Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: af20fae8-11ef-11eb-b10d-000c29e5a6cd.
2020-10-19T09:44:29.799484Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-10-19T09:44:29.803534Z 1 [Note] A temporary password is generated for root@localhost: sgpi1,o*?h7M
# 上一行末尾就是在localhost登陆的初始密码

# 创建启动服务
cp support-files/mysql.server /etc/init.d/mysql

# 启动服务
service mysql start

3.3 建立开机启动

# 编辑/etc/profile
vi /etc/profile
# 追加下面配置
export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin

# 使配置生效
source /etc/profile

# 增加开机启动
chkconfig --add mysql
chkconfig --level 2345 mysql on

3.4 连接数据库

# 连接数据库,密码为步骤3.2初始化时生成的密码
mysql -u root -p

# 修改密码
set password=password('123456');

# 支持远程访问
update user set host='%' where user='root';

# 权限刷新(重新从数据库加载配置)
flush privileges;

4、连接

经测试使用命令行mysql -u root -p和是mysql工具都能正常连接。

注意: 如果远程连接未生效,请检查防火墙是否关闭。

# 查看防火墙状态
systemctl status firewalld
# 关闭防火墙
systemctl stop firewalld
# 开启防火墙
systemctl start firewalld
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值