设为首页 收藏本站
查看: 770|回复: 0

[经验分享] 11.1 LAMP架构介绍 11.2 MySQL、MariaDB介绍 11.3/11.4/11.5 MySQL安装

[复制链接]

尚未签到

发表于 2018-10-7 12:04:40 | 显示全部楼层 |阅读模式
# 11.3 MySQL 安装 (上)  

  
- MySQL的几个常用安装包:rpm、源码、二进制免编译
  
- 二进制免编译(发布之前在linux服务器上租了一个编译,编译完了之后,把编译完成的文件重新安排,放到一个目录下去,然后打包压缩,发布)有一个好处,不用花那么多时间去配置,直接拿来用就可以
  
- rpm 包有一个缺点,没有办法去定义你所安装的路径,默认就安装在/usr下
  
- 二进制免编译包可以放在一个目录下,比如说/urs/local/src下,也可以放在别的目录下,随便你自己
  
- 二进制免编译包毕竟在其他编辑器上编辑的,如果想追求极致的性能,就自己去编译
  
- 如果工作中没有特殊的要求,可以用二进制免编译包就可以。
  

  

  

  
- 先进入到目录 /usr/local/src
  
```
  
[root@aminglinux-001 ~]# cd /usr/local/src/
  
[root@aminglinux-001 src]# ls
  
httpd-2.4.27  httpd-2.4.27.tar.gz
  
```
  
- 用命令uname -a 查看当前系统版本,x86_64 这个是64位的
  
- 可以去r.aminglinux.com 下载地址 ,我们这边下载5.6_64位二进制包
  
```
  
[root@aminglinux-001 src]# uname -a
  
Linux aminglinux-001 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
  
[root@aminglinux-001 src]#
  
```
  
- 使用wget下载
  
```
  
[root@aminglinux-001 src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2
  
--2017-09-19 23:06:16--  http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_
  
正在解析主机 mirrors.sohu.com (mirrors.sohu.com)... 221.236.12.140
  
正在连接 mirrors.sohu.com (mirrors.sohu.com)|221.236.12.140|:80... 已连接。
  
已发出 HTTP 请求,正在等待回应... 200 OK
  
长度:314581668 (300M) [application/octet-stream]
  
正在保存至: “mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz”
  

  
12% [============>                                                                               100%[======================================================>] 314,581,668  486KB/s 用时 18m 3s
  

  
2017-09-19 23:24:19 (284 KB/s) - 已保存 “mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz” [314581668/314581668])
  

  
[root@aminglinux-001 src]#
  
```
  

  

  

  

  
# 11.4 MySQL 安装 (中)
  
- 下载完之后第一步是要解压,
  
```
  
[root@aminglinux-001 src]# ls
  
httpd-2.4.27  httpd-2.4.27.tar.gz  mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
  

  
[root@aminglinux-001 src]# tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
  
.
  
.
  
.
  
mysql-5.6.35-linux-glibc2.5-x86_64/mysql-test/include/stop_slave.inc
  
mysql-5.6.35-linux-glibc2.5-x86_64/mysql-test/mysql-test-run.pl
  
mysql-5.6.35-linux-glibc2.5-x86_64/mysql-test/purify.supp
  
mysql-5.6.35-linux-glibc2.5-x86_64/mysql-test/valgrind.supp
  
```
  
- 挪目录到local目录下 并且改名mysql(mysql也是目录), mv /usr/local/mysql,然后到mysql目录下
  
```
  
[root@aminglinux-001 src]# mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql
  
[root@aminglinux-001 src]# cd /usr/local/mysql/
  
[root@aminglinux-001 mysql]# ls
  
bin      data  include  man         README   share      support-files
  
COPYING  docs  lib      mysql-test  scripts  sql-bench
  
[root@aminglinux-001 mysql]#
  
```
  

  
- 创建mysql用户,创建目录/data/
  
```
  
[root@aminglinux-001 mysql]# useradd mysql
  
[root@aminglinux-001 mysql]# mkdir /data/
  
mkdir: 无法创建目录"/data/": 文件已存在
  
[root@aminglinux-001 mysql]# ls /data/
  
liurongluan
  
[root@aminglinux-001 mysql]#
  
```
  
- 运行./scripts/mysql_install_db --user=mysql --datadir=/data/mysql 初始化
  
```
  
[root@aminglinux-001 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
  
FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
  
Data::Dumper
  
[root@aminglinux-001 mysql]#
  
```
  
- 现在报错了, please install the following Perl modules before executing 提示少了一个perl模块,名字是Dumper,尝试搜索一下
  
```
  
[root@aminglinux-001 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
  
FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
  
Data::Dumper
  
[root@aminglinux-001 mysql]# yum list |grep perl |grep -i dumper
  
perl-Data-Dumper.x86_64                 2.145-3.el7                    base
  
perl-Data-Dumper-Concise.noarch         2.020-6.el7                    epel
  
perl-Data-Dumper-Names.noarch           0.03-17.el7                    epel
  
perl-XML-Dumper.noarch                  0.81-17.el7                    base
  
[root@aminglinux-001 mysql]#
  
```
  
- 安装第四个试下 perl-XML-Dumper
  
```
  
[root@aminglinux-001 mysql]# yum install -y perl-XML-Dumper
  
已加载插件:fastestmirror
  
base                                                                     | 3.6 kB  00:00:00
  
epel/x86_64/metalink
  

  

  
已安装:
  
  perl-XML-Dumper.noarch 0:0.81-17.el7
  

  
作为依赖被安装:
  
  perl-XML-Parser.x86_64 0:2.41-10.el7
  

  
完毕!
  
[root@aminglinux-001 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
  
FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
  
Data::Dumper
  
[root@aminglinux-001 mysql]#
  
```
  
- 还是不行,再试下第一个包 perl-Data-Dumper
  
```
  
[root@aminglinux-001 mysql]# yum install -y perl-Data-Dumper
  
已加载插件:fastestmirror
  
Loading mirror speeds from cached hostfile
  
* epel: mirrors.tuna.tsinghua.edu.cn
  

  

  

  
已安装:
  
  perl-Data-Dumper.x86_64 0:2.145-3.el7
  

  
完毕!
  
[root@aminglinux-001 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
  
Installing MySQL system tables...2017-09-23 13:01:36 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
  
2017-09-23 13:01:36 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
  
2017-09-23 13:01:36 0 [Note] ./bin/mysqld (mysqld 5.6.35) starting as process 2630 ...
  
2017-09-23 13:01:36 2630 [Note] InnoDB: Using atomics to ref count buffer pool pages
  
2017-09-23 13:01:36 2630 [Note] InnoDB: The InnoDB memory heap is disabled
  

  

  

  
Support MySQL by buying support/licenses at http://shop.mysql.com
  

  
New default config file was created as ./my.cnf and
  
will be used by default by the server when you start it.
  
You may edit this file to change server settings
  

  
WARNING: Default config file /etc/my.cnf exists on the system
  
This file will be read by default by the MySQL server
  
If you do not want to use this, either remove it, or use the
  
--defaults-file argument to mysqld_safe when starting the server
  

  
[root@aminglinux-001 mysql]#
  

  
```
  
-  可以了,怎么查看一个命令执行完后 是否正确? 再上一个命令运行完之后 echo $? 结果是0 就是正确的,是1就是错误的
  
```
  

  
[root@aminglinux-001 mysql]# echo $?
  
0
  
[root@aminglinux-001 mysql]#
  
```
  
-  初始化完成,下面就是拷贝配置文件和启动脚本,配置文件在哪?在这个目录下support-files/
  
```
  
[root@aminglinux-001 mysql]# ls support-files/
  
binary-configure  magic  my-default.cnf  mysqld_multi.server  mysql-log-rotate  mysql.server
  
[root@aminglinux-001 mysql]#
  

  
[root@aminglinux-001 mysql]# ls support-files/my-default.cnf
  
support-files/my-default.cnf
  
```
  
-  这里面大部分都是注释文件
  
```
  
[root@aminglinux-001 mysql]# vi support-files/my-default.cnf
  

  
# For advice on how to change settings please see
  
# http://dev.mysql.com/doc/refman/5.6/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]
  

  
# Remove leading # and set to the amount of RAM for the most important data
  
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
  
# innodb_buffer_pool_size = 128M
  

  
# Remove leading # to turn on a very important data integrity option: logging
  
# changes to the binary log between backups.
  
# log_bin
  

  
# These are commonly set, remove the # and set as required.
  
# basedir = .....
  
# datadir = .....
  
# port = .....
  
# server_id = .....
  
# socket = .....
  

  
# Remove leading # to set options mainly useful for reporting servers.
  
# The server defaults are faster for transactions and fast SELECTs.
  
# Adjust sizes as needed, experiment to find the optimal values.
  
"support-files/my-default.cnf" 31L, 1126C
  

  
```
  
-  下面就是拷贝配置文件和启动脚本
  
```
  
[root@aminglinux-001 mysql]# cp support-files/my-default.cnf /etc/my.cnf^C
  
```
  
- 拷贝之前 也可以看下系统自带的my.cnf 文件,要用自带的my.conf 需要修改里面配置文件
  
```
  
[root@aminglinux-001 mysql]# ls /etc/my.cnf
  
/etc/my.cnf
  
[root@aminglinux-001 mysql]# rpm -qf /etc/my.cnf
  
mariadb-libs-5.5.52-1.el7.x86_64
  
[root@aminglinux-001 mysql]#
  

  
[root@aminglinux-001 mysql]# vim /etc/my.cnf
  

  
[mysqld]
  
datadir=/var/lib/mysql
  
socket=/var/lib/mysql/mysql.sock
  
# Disabling symbolic-links is recommended to prevent assorted security risks
  
symbolic-links=0
  
# Settings user and group are ignored when systemd is used.
  
# If you need to run mysqld under a different user or group,
  
# customize your systemd unit file for mariadb according to the
  
# instructions in http://fedoraproject.org/wiki/Systemd
  

  
[mysqld_safe]
  
log-error=/var/log/mariadb/mariadb.log
  
pid-file=/var/run/mariadb/mariadb.pid
  

  
#
  
# include all files from the config directory
  
```
  
- 需要修改/etc/my.cnf  用默认的配置文件
  
```
  
[mysqld]
  
datadir=/data/mysql
  
socket=/tmp/mysql/mysql.sock
  
# Disabling symbolic-links is recommended to prevent assorted security risks
  
symbolic-links=0
  
# Settings user and group are ignored when systemd is used.
  
# If you need to run mysqld under a different user or group,
  
# customize your systemd unit file for mariadb according to the
  
# instructions in http://fedoraproject.org/wiki/Systemd
  

  
[mysqld_safe]
  
#log-error=/var/log/mariadb/mariadb.log
  
#pid-file=/var/run/mariadb/mariadb.pid
  

  
#
  
# include all files from the config directory
  
#
  
#!includedir /etc/my.cnf.d
  

  
~
  
:wq
  
```
  
- 再一个就是它的启动脚本
  
```
  
[root@aminglinux-001 mysql]# ls
  
bin      data  include  man     mysql-test  scripts  sql-bench
  
COPYING  docs  lib      my.cnf  README      share    support-files
  
[root@aminglinux-001 mysql]#
  
```
  

  

  

  

  

  

  

  

  
# 11.5 MySQL 安装 (下)
  
- 再一个就是它的启动脚本
  
```
  
[root@aminglinux-001 mysql]# ls
  
bin      data  include  man     mysql-test  scripts  sql-bench
  
COPYING  docs  lib      my.cnf  README      share    support-files
  
[root@aminglinux-001 mysql]#
  

  
[root@aminglinux-001 mysql]# ls support-files/
  
binary-configure  my-default.cnf       mysql-log-rotate
  
magic             mysqld_multi.server  mysql.server
  
```
  
- 把support-files/mysql.server脚本   拷贝到 改名 /etc/init.d/mysqld
  
```
  
[root@aminglinux-001 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
  
[root@aminglinux-001 mysql]#
  

  
[root@aminglinux-001 mysql]# vi /etc/init.d/mysqld
  
# If you want to affect other MySQL variables, you should make your changes
  
# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.
  

  
# If you change base dir, you must also change datadir. These may get
  
# overwritten by settings in the MySQL configuration files.
  

  
basedir=
  
datadir=
  

  
-- INSERT --
  
```
  
- 改下basedir   datadir
  
```
  

  
# If you change base dir, you must also change datadir. These may get
  
# overwritten by settings in the MySQL configuration files.
  

  
basedir=/usr/local/mysql
  
datadir=/data/mysql
  

  
:wq
  
```
  

  
-  看下权限是755
  
```
  
[root@aminglinux-001 mysql]# vi /etc/init.d/mysqld
  
[root@aminglinux-001 mysql]# ls -l /etc/init.d/mysqld
  
-rwxr-xr-x 1 root root 10902 9月  23 13:27 /etc/init.d/mysqld
  
[root@aminglinux-001 mysql]#
  
```
  

  
- 如果想让它开机启动,需要把它加入到系统服务列表里去 下次开机会自动启动
  
```
  
[root@aminglinux-001 mysql]# chkconfig --add mysqld
  
[root@aminglinux-001 mysql]# chkconfig --list
  

  
注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。
  
      如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
  
      欲查看对特定 target 启用的服务请执行
  
      'systemctl list-dependencies [target]'。
  

  
mysqld         0:关1:关2:开3:开4:开5:开6:关
  
netconsole     0:关1:关2:关3:关4:关5:关6:关
  
network        0:关1:关2:开3:关4:关5:关6:关
  
[root@aminglinux-001 mysql]#
  

  
```
  

  

  

  
- 同样的,也可以直接用命令把它启动起来
  
/etc/init.d/mysql start
  
- 也可以这样service mysqld start
  
```
  

  
[root@aminglinux-001 mysql]# ls -l /etc/init.d/mysqld
  
-rwxr-xr-x 1 root root 10875 9月  23 18:13 /etc/init.d/mysqld
  
[root@aminglinux-001 mysql]# chmod 755 /etc/init.d/mysqld
  
[root@aminglinux-001 mysql]# vim /etc/init.d/mysqld
  
[root@aminglinux-001 mysql]# chkconfig --add mysqld
  
[root@aminglinux-001 mysql]# chkconfig mysqld on
  
[root@aminglinux-001 mysql]# service mysqld start
  
Starting MySQL.Logging to '/data/mysql/aminglinux-001.err'.
  
.. SUCCESS!
  
[root@aminglinux-001 mysql]#
  
```
  

  
- 查看下服务 是否有,看下进程
  
```
  
[root@aminglinux-001 mysql]# ps aux |grep mysql
  
root       6110  0.0  0.1  11764  1580 pts/0    S    18:15   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/aminglinux-001.pid
  
mysql      6320  0.8 45.6 973052 456580 pts/0   Sl   18:15   0:01 /usr/local/mysq/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/aminglinux-001.err --pid-file=/data/mysql/aminglinux-001.pid --socket=/tmp/mysql.sock --port=3306
  
root       6386  0.0  0.0 112664   976 pts/0    S+   18:19   0:00 grep --color=auto mysql
  
[root@aminglinux-001 mysql]# netstat -lntp
  
Active Internet connections (only servers)
  
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
  
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1131/sshd
  
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1648/master
  
tcp6       0      0 :::3306                 :::*                    LISTEN      6320/mysqld
  
tcp6       0      0 :::22                   :::*                    LISTEN      1131/sshd
  
tcp6       0      0 ::1:25                  :::*                    LISTEN      1648/master
  
[root@aminglinux-001 mysql]#
  
```
  

  
- 如果说有一天你没有办法把启动脚本放到/etc/init.d/  下去,或者说你根本就没有这样的启动模板去拷贝,可以用这种方法去启动
  
-  首先我们先给mysqld 停掉
  
```
  
[root@aminglinux-001 mysql]# service mysqld stop
  
Shutting down MySQL.. SUCCESS!
  
[root@aminglinux-001 mysql]# !ps
  
ps aux |grep mysql
  
root       6427  0.0  0.0 112664   972 pts/0    S+   18:23   0:00 grep --color=auto mysql
  
```
  
- 使用这种方法命令行的方式启动
  
```
  
[root@aminglinux-001 mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql &
  
[2] 6716
  
[1]   完成                  /usr/local/mysql/bin/mysqld_safe --default-file=/etc/my.cnf --user=mysql --datadir=/data/mysql
  
[root@aminglinux-001 mysql]# 170923 18:28:43 mysqld_safe Logging to '/data/mysql/aminglinux-001.err'.
  
170923 18:28:43 mysqld_safe Starting mysqld daemon with databases from /data/mysql
  
[root@aminglinux-001 mysql]#
  
[root@aminglinux-001 mysql]# ps aux |grep mysql
  
root       6716  0.0  0.1 113256  1584 pts/0    S    18:28   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql
  
mysql      6914  0.5 45.4 973052 454888 pts/0   Sl   18:28   0:00 /usr/local/mysql/binmysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/aminglinux-001.err --pid-file=/data/mysql/aminglinux-001.pid --socket=/tmp/mysql.sock --port=3306
  
root       6937  0.0  0.0 112664   976 pts/0    S+   18:29   0:00 grep --color=auto mysql
  
[root@aminglinux-001 mysql]#
  
[root@aminglinux-001 mysql]# netstat -lntp
  
Active Internet connections (only servers)
  
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
  
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1131/sshd
  
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1648/master
  
tcp6       0      0 :::3306                 :::*                    LISTEN      6914/mysqld
  
tcp6       0      0 :::22                   :::*                    LISTEN      1131/sshd
  
tcp6       0      0 ::1:25                  :::*                    LISTEN      1648/master
  
[root@aminglinux-001 mysql]#
  
```
  
- 那怎么去关呢,可以用killall mysqld 命令 把这个服务停掉
  
```
  
[root@aminglinux-001 mysql]# killall mysqld
  
[root@aminglinux-001 mysql]# 170923 18:32:07 mysqld_safe mysqld from pid file /data/mysql/aminglinux-001.pid ended
  
[root@aminglinux-001 mysql]# !ps
  
ps aux |grep mysql
  
root       6950  0.0  0.0 112664   976 pts/0    R+   18:32   0:00 grep --color=auto mysq
  
[2]+  完成                  /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf
  
[root@aminglinux-001 mysql]#
  
```
  

  
-  建议大家用killall 安全一些,先停止当前的写读操作,把那些没有完成磁盘写入的数据写到磁盘里去,知道写完之后 才把进程杀死,
  
-  如果以后遇到 mysqld 的进程 适中杀不死,等了好久没有把进程杀死ps 还有进程,那说明你的数据量很大,正在慢慢的写入磁盘离去,不要强制用kill  ,很容易导致数据丢失,就慢慢的等就好了,
  
-  mysql 有俩个引擎 一个是innodb  一个是  myisam(存储量比较小)
  

  

  

  

  

  

  

  

  
## 扩展
  
- mysql5.5源码编译安装 http://www.aminglinux.com/bbs/thread-1059-1-1.html
  

  
- MYSQL5.5源码安装 linux下  ,首先安装必要的库
  
```
  
yum -y install gcc*
  
###### 安装 MYSQL ######
  
首先安装camke
  
一、支持YUM,则
  
yum install -y cmake
  
二、也可以源码安装
  
cd /usr/local/src
  
#下载cmake
  
wget http://www.cmake.org/files/v2.8/cmake-2.8.7.tar.gz
  
tar zxvf cmake-2.8.7.tar.gz
  
cd cmake-2.8.7
  
#安装cmake
  
./configure
  
make
  
make install
  
安装 MYSQL
  
官网下载 MYSQL5.5版本 linux下源码包
  
http://dev.mysql.com/downloads/
  
安装
  
groupadd mysql
  
useradd -g mysql mysql
  
tar zxvf mysql-5.2.25.tar.gz
  
cd mysql-5.2.25
  
#cmake  .              //默认情况下安装,安装目录为/usr/local/mysql  数据目录为/usr/local/mysql/data
  
#也可以指定参数安装,如指定UTF8,数据引擎等
  
#具体参照http://dev.mysql.com/doc/refman/ ... ration-options.html
  
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mysql/data -DDEFAULT_CHARSET=utf8  -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=all -DWITH_DEBUG=0 -DWITH_SSL=yes -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1
  
make && make install
  
cd /usr/local/mysql
  
chown -R mysql:mysql  /usr/local/mysql
  
./scripts/mysql_install_db --user=mysql  -datadir=/mysql/data
  
#此处如不指定datadir,到启动时会报错
  
chown -R root .
  
chown -R mysql data
  
cp support-files/my-medium.cnf /etc/my.cnf
  
bin/mysqld_safe --user=mysql &
  
# Next command is optional
  
cp support-files/mysql.server /etc/init.d/mysqld
  
chmod +x /etc/init.d/mysqld
  
/etc/init.d/mysqld start
  
```
  
到此,安装完成
  

  

  

  

  

  

  

  

  
- mysql5.7二进制包安装(变化较大) http://www.apelearn.com/bbs/thread-10105-1-1.html
  

  
- mysql5.7 二进制包安装
  

  
```
  
1. 下载包
  

  
wget   http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz
  

  
若该链接失效,请到r.aminglinux.com 找最新的下载地址。
  

  
2. 解压
  

  
tar  xxvf mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz
  

  
mv  mysql-5.7.12-linux-glibc2.5-x86_64  /usr/local/mysql
  

  
3. 初始化
  

  
useradd -M -s /sbin/nologin  mysql
  

  
mkdir -p /data/mysql
  

  
chown mysql /data/mysql
  

  
cd /usr/local/mysql
  

  
./bin/mysqld  --initialize --user=mysql --datadir=/data/mysql
  

  
注意,这一步最后一行会有一个提示
  

  
[Note] A temporary password is generated for root@localhost: B*s1i(*,kXwg
  

  
最后面的字符串为root密码。
  

  
./bin/mysql_ssl_rsa_setup --datadir=/data/mysql
  

  
4. 拷贝配置文件和启动脚本
  

  
cp support-files/my-default.cnf  /etc/my.cnf
  

  
vim /etc/my.cnf //编辑或者修改
  

  
basedir = /usr/local/mysql
  

  
datadir = /data/mysql
  

  
port = 3306
  

  
socket = /tmp/mysql.sock
  

  
cp support-files/mysql.server /etc/init.d/mysqld
  

  
vi /etc/init.d/mysqld   //编辑或者修改
  

  
basedir=/usr/local/mysql
  

  
datadir=/data/mysql
  

  
5. 启动服务
  

  
/etc/init.d/mysqld start
  

  
6. 设置root密码
  

  
使用初始化密码登录
  

  
/usr/local/mysql/bin/mysql -uroot -p'B*s1i(*,kXwg'  //进入后直接设置密码
  

  
mysql>set password = password('mypass');   //一定要设置一下新密码
  

  
退出来,再使用新的密码登录就可以了
  

  
还有一种情况,就是不知道初始化密码
  

  
vi /etc/my.cnf
  

  
在[mysqld]下面增加一行
  

  
skip-grant-tables
  

  
重启  /etc/init.d/mysqld restart
  

  
/usr/local/mysql/bin/mysql -uroot
  

  
mysql> update user set authentication_string=password('123333') where user='root';
  

  
退出来后,更改my.cnf,去掉刚加的 skip-grant-tables
  

  
重启 /etc/init.d/mysqld restart
  
```
  

  
- 此时就可以使用新的密码了。



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-614316-1-1.html 上篇帖子: 浅谈mysql主从复制高可用 下篇帖子: Mysql数据库高可用
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表