MySQL压缩包安装教程-二进制
一、MySQL安装包下载方法
1.1 官网下载教程
https://dev.mysql.com/downloads/mysql/
https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
1.2 网易开源镜像站下载
http://mirrors.163.com/mysql/Downloads/
二、安装教程
2.1 安装包下载与解压
[root@ansible ~]# wget http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz [root@ansible ~]# tar zxvf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ [root@ansible local]# mv mysql-5.7.31-linux-glibc2.12-x86_64/ mysql
2.2 创建必要目录
[root@ansible ~]# mkdir -p /mysql/{data,sock,logs,pid,tmp,redo} [root@ansible ~]# ll /mysql/ total 0 drwxr-xr-x 2 root root 6 Jul 3 13:45 data drwxr-xr-x 2 root root 6 Jul 3 13:45 log drwxr-xr-x 2 root root 6 Jul 3 13:45 pid drwxr-xr-x 2 root root 6 Jul 3 13:45 sock
2.3 创建组和用户
[root@ansible ~]# groupadd mysql # 创建mysql组 [root@ansible ~]# useradd mysql -g mysql -d /usr/local/mysql -s /sbin/nologin # 添加mysql用户,并添加到mysql组里,主目录是/usr/local/mysql,账号不能登录系统
2.4 安装部署
(1)修改主配置文件
[root@ansible ~]# vim /etc/my.cnf [client] port=3306 socket=/mysql/sock/mysql.sock default-character-set=utf8 [mysqld] server-id=1 user=mysql port=3306 log-bin=mysql-bin binlog_format=ROW basedir=/usr/local/mysql datadir=/mysql/data tmpdir=/mysql/tmp socket=/mysql/sock/mysql.sock pid-file=/mysql/pid/mysql.pid log-error=/mysql/logs/mysql-error.log slow_query_log_file=/mysql/logs/slow.log innodb_data_file_path=ibdata1:2G:autoextend innodb_log_group_home_dir=/mysql/redo innodb_file_per_table=1 symbolic-links=0 default-storage-engine=INNODB character_set_server=utf8 collation-server=utf8_general_ci transaction_isolation=REPEATABLE-READ sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES skip_ssl # 禁用ssl mode在[mysqld]下配置(独占一行) default-time-zone='+8:00' innodb_buffer_pool_instances=1 max_connections=200
(2)启动服务文件
[root@ansible ~]# cd /usr/local/mysql/support-files/ [root@ansible support-files]# cp mysql.server /etc/init.d/mysqld [root@ansible support-files]# vim /etc/init.d/mysqld # 修改启动文件 basedir=/usr/local/mysql datadir=/mysql/data
(3)变更目录权限
[root@ansible ~]# chown -R mysql:mysql /mysql [root@ansible ~]# chown -R mysql:mysql /etc/my.cnf [root@ansible ~]# chown -R mysql:mysql /usr/local/mysql
(4)初始化MySQL数据库
[root@ansible ~]# cd /usr/local/mysql/bin [root@ansible bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/mysql/data # 初始化数据库 [root@ansible ~]# cat /mysql/log/mysql-error.log # 查看初始密码 2021-07-03T06:06:58.664699Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2021-07-03T06:06:59.049843Z 0 [Warning] InnoDB: New log files created, LSN=45790 2021-07-03T06:06:59.113871Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2021-07-03T06:06:59.179865Z 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: e084b4e1-dbc4-11eb-b13a-52540012414e. 2021-07-03T06:06:59.180677Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2021-07-03T06:07:00.151643Z 0 [Warning] CA certificate ca.pem is self signed. 2021-07-03T06:07:00.224202Z 1 [Note] A temporary password is generated for root@localhost: ,&,L-fGSq8Wn
(5)MySQL数据库加密
[root@ansible bin]# pwd /usr/local/mysql/bin [root@ansible bin]# ./mysql_ssl_rsa_setup --datadir=/mysql/data Generating a 2048 bit RSA private key ..........................................................+++ ........+++ writing new private key to 'ca-key.pem' ----- Generating a 2048 bit RSA private key ............................+++ ......................+++ writing new private key to 'server-key.pem' ----- Generating a 2048 bit RSA private key ................................+++ ....................................+++ writing new private key to 'client-key.pem' -----
(6)启动MySQL数据库
[root@ansible ~]# service mysqld start Starting MySQL. SUCCESS! [root@ansible ~]# ps -ef |grep mysql root 13153 1 0 14:11 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/mysql/data --pid-file=/mysql/data/ansible.pid mysql 13238 13153 1 14:11 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=ansible.err --pid-file=/mysql/data/ansible.pid root 13301 915 0 14:11 pts/0 00:00:00 grep --color=always -E mysql
(7)本地root用户登录mysql初始化远程登录用户
[root@ansible ~]# service mysqld start [root@ansible ~]# cp /usr/local/mysql/bin/mysql /usr/bin/ [root@ansible ~]# mysql -uroot -h127.0.0.1 -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 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> mysql> set password=password('123456'); Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> grant all privileges on *.* to root@'%' identified by '123456'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> select host,user from mysql.user; +-----------+---------------+ | host | user | +-----------+---------------+ | % | root | | localhost | mysql.session | | localhost | mysql.sys | | localhost | root | +-----------+---------------+ 4 rows in set (0.00 sec)
2.5 其它配置
(1)设置MySQL服务开机自启动
[root@ansible ~]# chkconfig --add mysqld [root@ansible ~]# chkconfig mysqld on [root@ansible ~]# chkconfig --list | grep mysqld [root@ansible ~]# systemctl list-dependencies default.target ● ├─acpid.service ● ├─auditd.service ● ├─avahi-daemon.service ● ├─blackbox_exporter.service ● ├─brandbot.path ● ├─crond.service ● ├─dbus.service ● ├─denyhosts.service ● ├─grafana-server.service ● ├─httpd.service ● ├─ipmi.service ● ├─iprdump.service ● ├─iprinit.service ● ├─iprupdate.service ● ├─irqbalance.service ● ├─kdump.service ● ├─mysqld.service ● ├─network.service ● ├─node_exporter.service ● ├─plymouth-quit-wait.service ● ├─plymouth-quit.service ● ├─prometheus.service ● ├─rc-local.service ● ├─rpcbind.service ● ├─rsyslog.service ● ├─sshd.service ● ├─sysstat.service ● ├─systemd-ask-password-wall.path ● ├─systemd-logind.service ● ├─systemd-readahead-collect.service ● ├─systemd-readahead-replay.service ● ├─systemd-update-utmp-runlevel.service
(2)配置MySQL环境变量
[root@ansible ~]# vim /etc/profile # 添加到最后一行 export MYSQL_HOME=/usr/local/mysql export PATH=$MYSQL_HOME/bin:$PATH [root@ansible ~]# source /etc/profile # 配置生效
(3)测试MySQL是否安装成功
[root@ansible ~]# mysql --version mysql Ver 14.14 Distrib 5.7.31, for linux-glibc2.12 (x86_64) using EditLine wrapper
三、常见报错解决
3.1 报错一
Error: ./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file:No such file or directory # 解决方案 [root@ansible ~]# yum install libaio* -y
3.2 报错二
Error: # ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/mysql/data 2021-07-05T03:39:51.400548Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2021-07-05T03:39:51.400615Z 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. 2021-07-05T03:39:51.400620Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set. 2021-07-05T03:39:51.402275Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting. 2021-07-05T03:39:51.402308Z 0 [ERROR] Aborting # 解决方案 (1)检查:配置文件没有问题 (2)检查:所有涉及文件已归属 mysql 用户没问题 (3)检查:数据库"bind-address"配置 (4)清空"/mysql/data"下编译的所有,即数据库文件,重新执行:./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/mysql/data
3.3 报错三
-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory # 解决方案 [root@ansible ~]# vim /etc/environment LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
3.4 报错四
【注】生产环境,密码复杂度策略要求越严格越好,为了方便实验,可以将密码复杂度降低。
mysql> CREATE USER 'xtrabackup'@'localhost' IDENTIFIED BY '12345678'; ERROR 1819 (HY000): Your password does not satisfy the current policy requirements mysql> show global variables like '%validate_password%'; +--------------------------------------+--------+ | Variable_name | Value | +--------------------------------------+--------+ | validate_password_check_user_name | OFF | | validate_password_dictionary_file | | | validate_password_length | 8 | | validate_password_mixed_case_count | 1 | | validate_password_number_count | 1 | | validate_password_policy | MEDIUM | | validate_password_special_char_count | 1 | +--------------------------------------+--------+ 7 rows in set (0.00 sec) set global validate_password_length=6; # 决定密码长度 set global validate_password_policy=0; # 决定密码复杂度,有以下三种配置 # 0 or LOW Length # 1 or MEDIUM Length; numeric, lowercase/uppercase, and special characters # 2 or STRONG Length; numeric, lowercase/uppercase, and special characters; dictionary file
作者:UStarGao
链接:https://www.starcto.com/mysql/177.html
来源:STARCTO
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
UCloud云平台推荐
随便看看
- 2021-05-21第三方常用工具收录
- 2021-03-03MongoDB安装部署与可视化
- 2022-03-15UCloud UHub镜像库隐藏福利-海外容器镜像加速
- 2021-06-12MySQL主从同步异常之跳过错误
- 2022-05-28MongoDB慢日志文件分析工具-mtools