二进制格式安装MySQL

下载二进制格式的mysql软件包

  1. 下载二进制格式的 mysql 软件包
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
.......
[root@localhost src]# ls
debug kernels mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
  1. 创建用户和组
[root@localhost ~]# groupadd -r mysql
[root@localhost ~]# useradd -M -r -s /sbin/nologin -g mysql mysql
  1. 解压软件至 /usr/local/
[root@localhost src]# tar zxvf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost src]# ls /usr/local/
bin etc games include lib lib64 libexec mysql-5.7.31-linux-glibc2.12-x86_64 sbin share src #做个软连接,方便操作
[root@localhost local]# ln -s mysql-5.7.31-linux-glibc2.12-x86_64 mysql
[root@localhost local]# ll
total 0
drwxr-xr-x. 2 root root 6 Nov 5 2016 bin
drwxr-xr-x. 2 root root 6 Nov 5 2016 etc
drwxr-xr-x. 2 root root 6 Nov 5 2016 games
drwxr-xr-x. 2 root root 6 Nov 5 2016 include
drwxr-xr-x. 2 root root 6 Nov 5 2016 lib
drwxr-xr-x. 2 root root 6 Nov 5 2016 lib64
drwxr-xr-x. 2 root root 6 Nov 5 2016 libexec
lrwxrwxrwx. 1 root root 35 Jan 8 13:10 mysql -> mysql-5.7.31-linux-glibc2.12-x86_64
drwxr-xr-x. 9 7161 31415 129 Jun 2 2020 mysql-5.7.31-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 6 Nov 5 2016 sbin
drwxr-xr-x. 5 root root 49 Dec 24 13:10 share
drwxr-xr-x. 2 root root 6 Nov 5 2016 src
  1. 修改目录 /usr/local/mysql 的属主属组
[root@localhost local]# chown -R mysql.mysql /usr/local/mysql*
[root@localhost local]# ll mysql
lrwxrwxrwx. 1 mysql mysql 35 Jan 8 13:10 mysql -> mysql-5.7.31-linux-glibc2.12-x86_64
  1. 添加环境变量
[root@localhost ~]# vim /etc/profile.d/mysql.sh
[root@localhost ~]# cat /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@localhost ~]# source /etc/profile.d/mysql.sh
[root@localhost ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
  1. 建立数据存放目录
[root@localhost ~]# mkdir /opt/data
[root@localhost ~]# chown -R mysql.mysql /opt/data/
[root@localhost ~]# ll -d /opt/data/
drwxr-xr-x. 2 mysql mysql 6 Jan 8 13:41 /opt/data/
  1. 初始化数据库
[root@localhost ~]# mysqld --initialize --user=mysql --datadir=/opt/data --basedir=/usr/local/mysql
2021-01-08T05:50:23.963006Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-01-08T05:50:24.553478Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-01-08T05:50:24.657628Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-01-08T05:50:24.732822Z 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: 67142018-5175-11eb-b9fe-000c29decd5a.
2021-01-08T05:50:24.735150Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-01-08T05:50:25.814369Z 0 [Warning] CA certificate ca.pem is self signed.
2021-01-08T05:50:26.196255Z 1 [Note] A temporary password is generated for root@localhost: CkIqTt7arh+f #注意:最后的'CkIqTt7arh+f'是登陆数据库的零时密码,这个是随机的,切记要牢记!
[root@localhost ~]# echo 'CkIqTt7arh+f' > pass #做个备份,以免忘记
  1. 修改配置文件(没有就创建一个)
[root@localhost ~]# cp /etc/my.cnf /etc/my.cnf.bak         #先做个备份
[root@localhost ~]# vim /etc/my.cnf
[root@localhost ~]# cat /etc/my.cnf
[mysqld]
datadir=/opt/data
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
port=3306
pid-file=/opt/data/mysql.pid
character-set-server=utf8
log-error=/var/log/mysqld.log
  1. 配置服务启动脚本
[root@localhost support-files]# pwd
/usr/local/mysql/support-files
[root@localhost support-files]# ls
magic mysqld_multi.server mysql-log-rotate mysql.server
[root@localhost support-files]# cp -a mysql.server /etc/init.d/mysqld
[root@localhost support-files]# vim /etc/init.d/mysqld
........
basedir=/usr/local/mysql #修改这两行参数
datadir=/opt/data
........
  1. 启动 mysql
[root@localhost ~]# service mysqld start
Starting MySQL. SUCCESS!
  1. 设置开机自动启动
[root@localhost ~]# chkconfig --list

Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'. netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost ~]# chkconfig --add mysqld #添加开机自动启动
[root@localhost ~]# chkconfig --list Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'. mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
  1. 修改密码
[root@localhost ~]# mysql -uroot -p'CkIqTt7arh+f'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.31 Copyright (c) 2000, 2020, 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('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

最新文章

  1. [LeetCode] Valid Parentheses
  2. 【黑金原创教程】【FPGA那些事儿-驱动篇I 】连载导读
  3. SQL 表变量和临时表
  4. ci实现RBAC,详细解释原理和核心代码显示
  5. 后台list 如何转换为json格式
  6. Spark Tungsten揭秘 Day4 内存和CPU优化使用
  7. 深入理解Javascript变量作用域
  8. SIEM
  9. Mac实用操作技巧(二)
  10. asp .net连接打开数据库初步
  11. IPFS开发团队是如何工作的?
  12. 《python for data analysis》第四章,numpy的基本使用
  13. JavaPoet开源项目的使用
  14. js 关键字 in 的使用方法
  15. mvc下ajax请求遇到session超时简单处理方式
  16. 【laravel5.4】git上clone项目到本地,配置和运行 项目报错:../vendor/aotuload.php不存在
  17. 文本相似度分析(基于jieba和gensim)
  18. KineticJS教程(10)
  19. Activiti - 新一代的开源 BPM 引擎 (zhuan)
  20. 北京电子科技学院(BESTI)实验报告2

热门文章

  1. [树形DP]战略游戏
  2. Qt开发技术:图形视图框架(一)基本介绍
  3. python进阶(7)--文件与异常
  4. Dynamics CRM实体系列之图表
  5. (一)LDAP 简介
  6. Day16_96_IO_available() 和 skip()方法
  7. Webpack的理解以及解决了的问题
  8. K8S(17)二进制的1.15版本部署hpa自动伸缩
  9. 鸿蒙HI3516-驱动开发(1.1-LTS)
  10. 解决mysql You can't specify target table for update in FROM clause错误