linux下安装及配置mysql5.7.29

下载安装包

下载地址 https://dev.mysql.com/downloads/mysql/5.7.html#downloads

在这里插入图片描述

选择 linux-generic
系统选64位进行下载

压缩包上传至linux环境并解压

使用root用户

mkdir -p /opt/mysql
tar -zxvf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz -C /opt/mysql/
添加mysql用户和组
#先检查是否存在该用户和组
grep mysql /etc/passwd
grep mysql /etc/group

#若不存在开始创建
groupadd mysql
useradd -r -g mysql mysql  #-r参数代表该用户为系统用户,不可用于登陆系统 -g指定组为mysql
创建data目录
cd /opt/mysql/mysql-5.7.29-linux-glibc2.12-x86_64
mkdir -p data
将用户和组改为mysql
chown -R mysql.mysql /opt/mysql/mysql-5.7.29-linux-glibc2.12-x86_64
在support-files目录下创建my_default.cnf
touch my_default.cnf
vi my_default.cnf

将如下内容粘到my_default.cnf中

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
 
 
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
 
basedir = /opt/mysql/mysql-5.7.29-linux-glibc2.12-x86_64
datadir = /opt/mysql/mysql-5.7.29-linux-glibc2.12-x86_64/data
port = 3306
socket = /tmp/mysql.sock
character-set-server=utf8
 
log-error = /opt/mysql/mysql-5.7.29-linux-glibc2.12-x86_64/data/mysqld.log
pid-file = /opt/mysql/mysql-5.7.29-linux-glibc2.12-x86_64/data/mysqld.pid
初始化 mysqld

在安装目录下执行以下命令

./bin/mysqld --initialize --user=mysql --basedir=/opt/mysql/mysql-5.7.29-linux-glibc2.12-x86_64/ --datadir=/opt/mysql/mysql-5.7.29-linux-glibc2.12-x86_64/data/ 

进入data目录下查看初始化完成后的日志

[root@walker001 data]# more mysqld.log 
2020-03-29T13:30:36.593124Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more detail
s).
2020-03-29T13:30:36.593164Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode
 in a future release.
2020-03-29T13:30:36.593166Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2020-03-29T13:30:36.865312Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-03-29T13:30:36.904633Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-03-29T13:30:36.959741Z 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: 7984d717-71c1-
11ea-9218-000c2979e0d7.
2020-03-29T13:30:36.960388Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-03-29T13:30:38.266384Z 0 [Warning] CA certificate ca.pem is self signed.
2020-03-29T13:30:38.819913Z 1 [Note] A temporary password is generated for root@localhost: B8b+Ee%kX70A

重点关注最后生成的临时密码
2020-03-29T13:30:38.819913Z 1 [Note] A temporary password is generated for root@localhost: B8b+Ee%kX70A

启动server脚本放到开机初始化目录
cd support-files
cp ./mysql.server /etc/init.d/mysql
启动mysql服务
[root@walker001 support-files]# service mysql start
Starting MySQL... SUCCESS! 
使用临时密码登陆mysql
cd /opt/mysql/mysql-5.7.29-linux-glibc2.12-x86_64
./bin/mysql -u root -p

此时报出如下异常

./bin/mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

是由于缺少组件导致,使用如下命令安装

yum install libncurses*

安装完成后再次执行命令即可登陆mysql

修改密码
mysql> set password=password('zwk95914');
Query OK, 0 rows affected, 1 warning (0.08 sec)

mysql> grant all privileges on *.* to root@'%' identified by 'zwk95914';
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> 
mysql> flush privileges;
Query OK, 0 rows affected (0.06 sec)
添加远程访问权限
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set host='%' where user = 'root';
ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'

报了error,说是已经存在,经查询的确已经有了

mysql> select host from user where user = 'root';
+-----------+
| host      |
+-----------+
| %         |
| localhost |
+-----------+
2 rows in set (0.02 sec)

再次刷新下表

mysql> flush privileges;

重启使配置生效

service mysql restart
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值