linux下安装mysql(离线版)

mysql-5.7.18-linux-glibc2.5-x86_64.tar
链接:https://pan.baidu.com/s/16JHbznmWY9QsEoG2qmhgkA
提取码:vizj
背景信息
本教程在示例步骤中使用了以下实例规格和版本软件。实际操作时,请以您的软件版本为准。
操作系统:公共镜像CentOS 7.2 64位
MySQL:5.7.33
本示例中,MySQL相关安装路径说明如下:
配置文件:/etc/my.cnf
数据存储:/usr/local/mysql/data/
命令文件:/usr/bin和/usr/sbin
数据库端口:3306
本文章是离线版安装
在线版安装见之前文章:https://blog.csdn.net/weixin_43914685/article/details/113838041

1.卸载系统自带的Mariadb

[root@slave1 ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@slave1 ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64

2.删除etc目录下的my.cnf文件

[root@slave1 local]# rm /etc/my.cnf
rm: cannot remove ?etc/my.cnf? No such file or directory
  1. 检查mysql组和用户是否存在,如无创建
[root@slave1 local]# cat /etc/group | grep mysql                         
[root@slave1 local]# cat /etc/passwd | grep mysql
[root@slave1 local]# groupadd mysql
[root@slave1 local]# useradd -g mysql mysql
  1. 制定password 为1qaz!QAZ
[root@slave1 local]# passwd mysql
Changing password for user mysql.
New password: 
BAD PASSWORD: The password is a palindrome
Retype new password: 
passwd: all authentication tokens updated successfully.

3.把mysql安装包上传到/usr/local目录

  1. 解压后文件名改为mysql
[root@slave1 ~]# cd /usr/local/
[root@slave1 local]# ls
mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
[root@slave1 local]# tar -zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
[root@slave1 local]# mv mysql-5.7.18-linux-glibc2.5-x86_64 mysql
  1. 更改所属的组和用户
[root@slave1 local]# chown -R mysql mysql/
[root@slave1 local]# chgrp -R mysql mysql/
[root@slave1 local]# cd mysql
[root@slave1 mysql]# mkdir data
[root@slave1 mysql]# chown -R mysql:mysql data
  1. 在etc下新建配置文件my.cnf,并在该文件内添加以下配置
[root@slave1 mysql]# vim /etc/my.cnf
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
skip-name-resolve
#设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M

4.安装和初始化

[root@slave1 mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/     
2021-02-17 17:40:02 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2021-02-17 17:40:05 [WARNING] The bootstrap log isn't empty:
2021-02-17 17:40:05 [WARNING] 2012-04-17T09:40:02.728710Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2021-02-17T09:40:02.729161Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2021-02-17T09:40:02.729167Z 0 [Warning] Changed limits: table_open_cache: 407 (requested 2000)
[root@slave1 mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@slave1 mysql]# chown 777 /etc/my.cnf 
[root@slave1 mysql]# chmod +x /etc/init.d/mysqld
  1. 启动mysql
[root@slave1 mysql]# /etc/init.d/mysqld restart
  1. 设置开机自启动
[root@slave1 mysql]# chkconfig --level 35 mysqld on
[root@slave1 mysql]# chkconfig --list mysqld
[root@slave1 mysql]# chmod +x /etc/rc.d/init.d/mysqld
[root@slave1 mysql]# chkconfig --add mysqld
[root@slave1 mysql]# chkconfig --list mysqld
[root@slave1 mysql]# service mysqld status
 SUCCESS! MySQL running (4475)
  1. 添加环境变量
[root@slave1 mysql]# vi /etc/profile
#mysql
export PATH=$PATH:/usr/local/mysql/bin
[root@slave1 mysql]# source /etc/profile
  1. 获取初始密码
[root@slave1 mysql]# cat /root/.mysql_secret
# Password set for user 'root@localhost' at 2021-02-17 19:40:40 
ewh7*oH(w!TP
  1. 修改密码
    输入刚才获取的密码,ewh7*oH(w!TP
[root@slave1 mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.18 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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 respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> set PASSWORD = PASSWORD('1qaz!QAZ');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.05 sec)
  1. 创建远程访问权限
    依次运行以下命令创建远程登录MySQL的账号。
    建议您使用非root账号远程登录MySQL数据库,本示例账号为lizhe、密码为1qaz!QAZ。
    注意 实际创建账号时,需将示例密码123456更换为符合要求的密码,并妥善保存。密码要求:长度为8至30个字符,必须同时包含大小写英文字母、数字和特殊符号。可以使用以下特殊符号:
    ()` ~!@#$%^&*-+=|{}[]:;‘<>,.?/
mysql> grant all on *.* to 'lizhe'@'%' IDENTIFIED BY '1qaz!QAZ';
Query OK, 0 rows affected, 1 warning (0.03 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

5.远程连接mysql测试

在这里插入图片描述
注意:
mysql配置文件位置

[root@master conf]# cat /etc/my.cnf
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值