获取MySQL软件
企业版:Enterprise , 互联网行业一般不选择. 社区版本:选择 源码包 编译安装: source code .tar.gz 通用二进制 你们公司用什么版本数据库? 具体什么小版本号? 5.6.20 5.6.34 5.6.36 5.6.38 5.6.40 5.7.18 5.7.20 5.7.22
通用二进制版本:
https://downloads.mysql.com/archives/community/
选择版本,再选择Operating System: Linux – Generic
源码包 版本:
https://downloads.mysql.com/archives/community/
选择版本,再选择Operating System: Soure Code
MySQL二进制安装
备注: 部署前需要先 yum remove mariadb*
1、创建软件目录:
[root@db01 ~]# mkdir -p /app/ 上传软件到此目录
2、解压并改名为mysql
[root@db01 app]# mv mysql-5.7.20-linux-glibc2.12-x86_64 mysql [root@db01 app]# ls -l /app/mysql/ total 36 drwxr-xr-x 2 root root 4096 Mar 4 14:55 bin -rw-r--r-- 1 7161 31415 17987 Sep 13 2017 COPYING drwxr-xr-x 2 root root 55 Mar 4 14:55 docs drwxr-xr-x 3 root root 4096 Mar 4 14:55 include drwxr-xr-x 5 root root 229 Mar 4 14:55 lib drwxr-xr-x 4 root root 30 Mar 4 14:55 man -rw-r--r-- 1 7161 31415 2478 Sep 13 2017 README drwxr-xr-x 28 root root 4096 Mar 4 14:55 share drwxr-xr-x 2 root root 90 Mar 4 14:55 support-files
修改环境变量:
vim /etc/profile #加入一行 export PATH=/app/mysql/bin:$PATH [root@db01 bin]# source /etc/profile
3、建立mysql用户和组(如果已有可忽略)
useradd mysql -s /sbin/nologin
4、创建相关目录并修改权限
mkdir /data/mysql -p chown -Rf mysql.mysql /app/* chown -Rf mysql.mysql /data/*
5、初始化数据(建库)
方法一:
初始化数据,初始化管理员的临时密码,屏幕会输出一个临时密码 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
常见报错:
报错原因: Linux系统中缺少libaio-devel 软件包 解决: yum install -y libaio-devel
报错原因: 在/data/mysql 存在文件 解决: \rm -rf /data/mysql/*
新特性重要说明:
6、5.7开始,MySQL加入了全新的 密码的安全机制:
1.初始化完成后,会生成临时密码(显示到屏幕上,并且会往日志中记一份)
2.密码复杂度:长度:超过12位? 复杂度:字符混乱组合
3.支持用户设置密码过期策略,要求用户在一定时间过后必须修改密码
(在5.7.11版本后都已经把默认值从360变成了0也就是永不过期了)
方法二:建议使用这种方法
初始化数据,初始化管理员的密码为空 # 如果已经初始化过了,就需要把数据目录数据情况,再次初始化 rm -rf /data/mysql/* [root@db01 ~]# mysqld --initialize-insecure --user=mysql --basedir=/app/mysql --datadir=/data/mysql 2019-04-18T03:37:43.146018Z 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:37:43.892132Z 0 [Warning] InnoDB: New log files created, LSN=45790 2019-04-18T03:37:43.970412Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2019-04-18T03:37:44.029490Z 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: 5378f3b3-618b-11e9-9164-000c294234c8. 2019-04-18T03:37:44.041469Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2019-04-18T03:37:44.042348Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option. [root@db01 ~]# cd /data/mysql/ [root@db01 mysql]# ll total 110628 -rw-r----- 1 mysql mysql 56 Apr 18 11:37 auto.cnf -rw-r----- 1 mysql mysql 419 Apr 18 11:37 ib_buffer_pool -rw-r----- 1 mysql mysql 12582912 Apr 18 11:37 ibdata1 -rw-r----- 1 mysql mysql 50331648 Apr 18 11:37 ib_logfile0 -rw-r----- 1 mysql mysql 50331648 Apr 18 11:37 ib_logfile1 drwxr-x--- 2 mysql mysql 4096 Apr 18 11:37 mysql drwxr-x--- 2 mysql mysql 8192 Apr 18 11:37 performance_schema drwxr-x--- 2 mysql mysql 8192 Apr 18 11:37 sys
注释:5.6初始化的区别
/application/mysql/scripts/mysql_install_db --user=mysql --datadir=/application/mysql/data --basedir=/application/mysql
7、编写默认配置文件
vim /etc/my.cnf [mysqld] user=mysql basedir=/app/mysql datadir=/data/mysql server_id=6 port=3306 socket=/tmp/mysql.sock [mysql] socket=/tmp/mysql.sock prompt="\\u@\\h:\\d>"
8、配置启动脚本:
[root@db01 mysql]# cd /app/mysql/support-files [root@db01 support-files]# ./mysql.server start Starting MySQL.Logging to '/data/mysql/db01.err'. SUCCESS! cp mysql.server /etc/init.d/mysqld
9、使用systemd管理mysql
vim /etc/systemd/system/mysqld.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=/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf LimitNOFILE = 5000 #reload从新加载下systemd systemctl daemon-reload
注意:将原来模式启动mysqld先关闭,然后再用systemd管理。
[root@db01 mysql]# cd /app/mysql/support-files [root@db01 support-files]# ./mysql.server stop
systemd 管理相关命令
systemctl start/stop/restart/status mysqld
10、安装后的简单管理
#修改密码
[root@db01 ~]# mysqladmin -uroot -p password fdaf 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.
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容