DBA

mysql的安装

1.创建软件目录
[root@db01 ~]# mkdir -p /data/app/ /data/3306/data  /data/3306/binlog
2.建立mysql用户和组(如果已有可忽略)
创建MySQL相关用户、组
[root@db01 ~]# useradd mysql
[root@db01 ~]# chown -R mysql.mysql /data
3 系统残留清空
[root@db01 ~]# yum remove mariadb-libs -y
4 软件上传和解压
[root@db01 ~]# cd /data/app 
[root@db01 app]# tar xf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz 
[root@db01 app]# ln -s mysql-5.7.28-linux-glibc2.12-x86_64 mysql
[root@db01 app]# chown -R mysql. /data
5 修改环境变量
vim /etc/profile
export PATH=$PATH:/data/app/mysql/bin
[root@db01 bin]# source /etc/profile
6 生效配置
source /etc/profile
7 检查设置
[root@db01 bin]# mysql -V
mysql  Ver 14.14 Distrib 5.7.28, for linux-glibc2.12 (x86_64) using  EditLine wrapper
8 准备基础配置文件
cat >/etc/my.cnf <<EOF 
[mysqld]
user=mysql
basedir=/data/app/mysql 
datadir=/data/3306/data
server_id=6
socket=/tmp/mysql.sock 
[client]
socket=/tmp/mysql.sock
EOF
9 解决初始化报错 安装依赖
yum install -y libaio-devel
10 初始化
初始化数据,初始化管理员的临时密码
mysqld --initialize  --user=mysql --basedir=/app/mysql --datadir=/data/mysql
2019-04-18T03:21:53.381108Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-04-18T03:21:54.583415Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-04-18T03:21:54.697859Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-04-18T03:21:54.760821Z 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: 1daa0c57-6189-11e9-bc80-000c294234c8.
2019-04-18T03:21:54.770856Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-04-18T03:21:54.772016Z 1 [Note] A temporary password is generated for root@localhost: 9LN.fh_Ea#uU
image.png

新特性重要说明

5.7开始,MySQL加入了全新的 密码的安全机制:
1.初始化完成后,会生成临时密码(显示到屏幕上,并且会往日志中记一份)
2.密码复杂度:长度:超过12位? 复杂度:字符混乱组合
3.密码过期时间180天

11 准备启动脚本

方法一: 自带脚本(适合于单机单MySQL)

[root@db01 ~]# cp /data/app/mysql/support-files/mysql.server /etc/init.d/mysqld

启动方式 1: SYS-V (C6服务管理方式)

配置启动脚本
[root@db01 ~]# service mysqld start /stop /restart
[root@db01 ~]# service mysqld start 
Starting MySQL.Logging to '/data/3306/data/db01.err'.
 SUCCESS! 
[root@db01 ~]# service mysqld stop
Shutting down MySQL.. SUCCESS! 
[root@db01 ~]# service mysqld restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL. SUCCESS! 
[root@db01 ~]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS! 

启动方式2: C7 管理方式 systemd

[root@db01 ~]# chkconfig --add mysqld
[root@db01 ~]# systemctl stop mysqld
[root@db01 ~]# systemctl start mysqld
[root@db01 ~]# systemctl restart mysqld
12 使用systemd管理mysql

方法二: 手动配置启动脚本

vim /etc/systemd/system/my.service 
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/data/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000

PS:注意

需要将之前启动过的mysql用老的方式关闭掉。再启动。
[root@db01 ~]# /etc/init.d/mysqld stop
Shutting down MySQL… SUCCESS!
[root@db01 ~]# systemctl start my.service

初始化命令的介绍
方法1:

mysqld --initialize-insecure --user=  --basedir= --datadir= 
提示: 
root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

特点:

  1. 空密码的管理员用户。
  2. 密码复杂度低。

方法2:

mysqld --initialize  --user=  --basedir= --datadir= 
A temporary password is generated for root@localhost: jwhscLjji5<3 

特点:

  1. 管理员用户生成默认密码,12位,4种复杂度。
  2. 临时密码不能用来管理数据库,第一次登陆前改掉它。

ps:5.7 以前版本初始化方式

/data/app/mysql/scripts/mysql_install_db  --user=  --basedir= --datadir= 
13 安装后的简单管理
[root@db01 ~]# mysqladmin -uroot -p password 123
Enter password: 
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
5.6版本:
select user,password,host from mysql.user;
5.7 中用户基本信息
select user,authentication_string,host from mysql.user;
desc  mysql.user;
小结:
1.版本 (主流版本的GA时间了解一下)
5.6 5.7 
5.6.38   5.7.20 
20170913 
(1) 初始化方式变了
mysql_install_db   
mysqld  --initialize-insecure
(2) 用户安全
12位
180
4种复杂度
(3)密码字段
authentication_strings
2.安装方法:
二进制
源码
yum 
3.建库(初始化数据库)
mysqld --intialize-insecure --user=mysql --basedir=/app/mysql --datadir=/data/mysql 
4.简易的配制文件/etc/my.cnf
user 
basedir
datadir 
server_id
port
socket 
	1. 管理员密码
mysqladmin -uroot -p password xx

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值