11.1 LAMP Architecture Introduction 11.2 MySQL, MariaDB Introduction 11.3/11.4/11.5 MySQL Installation

Posted by jpraj on Tue, 21 May 2019 20:58:43 +0200

11.1 Introduction to LAMP architecture

  •  Linux + Apache(httpd)+ MySQL + PHP 

  •  PHP website (Google, Taobao, Baidu, 51cto blog, ape class forum)

  •  The three roles can be in one machine or separate (httpd and PHP together)

  • Introduction to LAMP architecture

  • How httpd, PHP, MySQL work 

  • Apache (httpd) and PHP are a whole (PHP is a module combined with Apache)

  • But apache can't deal directly with mysql, etc. through PHP module, get data in MYSOL, PHP gives the result to apche, apache gives the user. This kind of operation behavior that PHP and mysql connect to fetch data is called dynamic behavior.

  • Visit a website, first sign in, when you log in, such a process, enter the web address in the browser, sign in, request handed over to apache, Apache first check to see if the request is dynamic or static, login this behavior needs to submit your username password to apache, Apache takes your username password, compares it in the database, and see if it isCorrect, deal with MySQL through the php module, find out what your username password is through mysql, and then compare php to see if it is right. If it is right, Apache will return you a login status, which is a dynamic request

  • Dynamic requests like users entering the ape class forum to enter their account passwords

  • For example, the picture you visit, the logo of the website, such as a logo of the forum you visit, this logo also needs to go to apache to request. apache gets the logo logo and it does not exist in MySQL. So you get this picture directly from the static file, which is also a directory on your linux server, and return it to the user directly. This process does not have any relationship with MySQ.L Interaction, this process is a static request

  • Static requests, such as viewing pictures, content of a website

  • MySQL can't store pictures or files. You can save some username passwords, credits, and replies to posts

Introduction to 11.2 MySQL_MariaDB

  • MySQL is a relational database developed by mysql ab, which was acquired by sun in 2008 (1 billion knives), and oracle in 2009 (7.4 billion knives).

  • MySQL official https://www.mysql.com latest version 5.7GA/8.0DMR

  • MySQL 5.6 has changed a lot and 5.7 performance has improved a lot

  • Mariadb is a branch of MySQL, the official website https://mariadb.com/latest version 10.2

  • MariaDB is maintained primarily by SkySQL, now renamed MariaDB, which was founded by the original MySQL author and led by most of the original crew.

  • Mariadb5.5 corresponds to MySQL 5.5, 10.0 corresponds to MySQL 5.6 Communities, Enterprise Enterprise Edition, GA (Generally Available) refers to the generic version, used in production environments, DMR (Development Milestone Release) development milestone release, RC (Release Candidate) release candidate, Beta open beta, Alpha internal test version

# 11.3 MySQL installation (top)

- MySQL Several common installation packages: rpm,Source, Binary Compile-Free
- Binary Compile-Free (before publishing) linux The server rents a compilation, after compilation, rearranges the compiled files, puts them in a directory, packages them, compresses them, and publishes them). There's one benefit: you don't have to spend so much time configuring them, you can just use them
- rpm Package has a disadvantage that it cannot define the path you install. It is installed by default/usr lower
- Binary decompile-free packages can be placed in a directory, such as/urs/local/src Next, you can put it in another directory, just for yourself
- Binary Compile-Free Packages are edited on other editors after all, so if you want the best performance, compile them yourself
- If there are no special requirements in your work, you can use binary decompile-free packages.



- Enter directory first /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
```
- With Command uname -a View the current system version,x86_64 This is 64-bit
- OK to go r.aminglinux.com Download Address ,Download 5 from here.6_64 Bit Binary Package
```
[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]# 
```
- Use wget download
```
[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_
//Resolving host mirrors.sohu.com (mirrors.sohu.com)... 221.236.12.140
//Connecting to mirrors.sohu.com (mirrors.sohu.com)|221.236.12.140|:80... Connected.
//HTTP request sent, waiting for response... 200 OK
//Length: 314581668 (300M) [application/octet-stream]
//Saving to:'mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz'

12% [============>                                                                               100%[======================================================>] 314,581,668  486KB/s Time-consuming 18m 3s 

2017-09-19 23:24:19 (284 KB/s) - Saved "mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz" [314581668/314581668])

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




# 11.4 MySQL installation (medium)
- The first step after downloading is to unzip,
```
[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
```
- Move directory to local Catalog And rename it mysql(mysql It's also a directory, mv /usr/local/mysql,Then to mysql Catalog
```
[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]# 
```

- Establish mysql User, create directory/data/
```
[root@aminglinux-001 mysql]# useradd mysql
[root@aminglinux-001 mysql]# mkdir /data/
mkdir: Unable to create directory"/data/": file already exist
[root@aminglinux-001 mysql]# ls /data/
liurongluan
[root@aminglinux-001 mysql]# 
```
- Function./scripts/mysql_install_db --user=mysql --datadir=/data/mysql Initialization
```
[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]# 
```
- Wrong report now, please install the following Perl modules before executing Tip missing one perl Module, name is Dumper,Try searching
```
[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]# 
```
- Install the fourth trial perl-XML-Dumper
```
[root@aminglinux-001 mysql]# yum install -y perl-XML-Dumper
//Plugin loaded: fastestmirror
base                                                                     | 3.6 kB  00:00:00     
epel/x86_64/metalink     


//Installed:
  perl-XML-Dumper.noarch 0:0.81-17.el7                                                          

//Installed as a dependency:
  perl-XML-Parser.x86_64 0:2.41-10.el7                                                          

//Complete!
[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]# 
```
- No, try the first package again perl-Data-Dumper
```
[root@aminglinux-001 mysql]# yum install -y perl-Data-Dumper
//Plugin loaded: fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirrors.tuna.tsinghua.edu.cn



//Installed:
  perl-Data-Dumper.x86_64 0:2.145-3.el7                                                         

//Complete!
[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]# 

```
-  Okay, how to see when a command is executed Is it correct? After the last command runs echo $? The result is 0 Is it right, is it wrong
```

[root@aminglinux-001 mysql]# echo $?
0
[root@aminglinux-001 mysql]# 
```
-  Initialization is complete. Here is a copy of the configuration file and the startup script. Where is the configuration file?In this directory 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
```
-  Most of this is annotation files
```
[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

```
-  Here's a copy of the configuration file and the startup script
```
[root@aminglinux-001 mysql]# cp support-files/my-default.cnf /etc/my.cnf^C
```
- Before copying You can also see the system's own my.cnf file,To use your own my.conf Need to modify the profile inside
```
[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
```
- Needs modification/etc/my.cnf  Use default profile
```
[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
```
- Another is its startup script
```
[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 installation (below)
- Another is its startup script
```
[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
```
- hold support-files/mysql.server Script   copy to Rename /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 --
```
- Change 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
```

-  Look at permission 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 month  23 13:27 /etc/init.d/mysqld
[root@aminglinux-001 mysql]# 
```

- If you want it to start, you need to add it to the list of system services Next opportunity starts automatically
```
[root@aminglinux-001 mysql]# chkconfig --add mysqld
[root@aminglinux-001 mysql]# chkconfig --list

//Note: The output only shows the SysV service and does not include the native systemd service.SysV configuration data may be overwritten by native systemd configuration. 
      If you want to list systemd service,Please execute 'systemctl list-unit-files'. 
      To view for a specific target Enabled services please execute
      'systemctl list-dependencies [target]'. 

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

```



- Similarly, you can start it directly with a command
/etc/init.d/mysql start
- This is also possible service mysqld start
```

[root@aminglinux-001 mysql]# ls -l /etc/init.d/mysqld
-rwxr-xr-x 1 root root 10875 9 month  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]# 
```

- View Services If so, look at the process
```
[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]# 
```

- If one day you can't put the startup script in/etc/init.d/  Go on, or say you don't have such a startup template to copy at all, you can start it this way
-  First let's give mysqld Stop
```
[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
```
- Start the command line this way
```
[root@aminglinux-001 mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql &
[2] 6716
[1]   complete                  /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]# 
```
- How can I turn it off? killall mysqld command Stop this service
```
[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]+  complete                  /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf
[root@aminglinux-001 mysql]# 
```

-  Suggest everybody to use killall It's safer to stop the current write-read operation and write data to disk that has not been written to, until it's done To kill the process,
-  If you encounter it later mysqld Process Moderate death, wait a long time without killing the process ps There is also a process, which means you have a large amount of data, slowly writing to disk and leaving, do not force kill  ,It's easy to lose data. Just wait.
-  mysql There are two engines One is innodb  One is  myisam(Storage is small)








## extend
- mysql5.5 Source Compilation Installation http://www.aminglinux.com/bbs/thread-1059-1-1.html

- MYSQL5.5 Source Installation linux lower  ,Install the necessary libraries first
```
yum -y install gcc*
###### install MYSQL ######
//Install camke first 
//1. Supporting YUM, then
yum install -y cmake
//2. Source installation is also possible
cd /usr/local/src
#Download 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
#Install cmake
./configure
make
make install
//Install MYSQL
//Official Download MYSQL5.5 linux Source Pack
http://dev.mysql.com/downloads/
//install
groupadd mysql
useradd -g mysql mysql
tar zxvf mysql-5.2.25.tar.gz
cd mysql-5.2.25
#cmake...) Install //By default, install directory is/usr/local/mysql, data directory is/usr/local/mysql/data
#You can also specify parameter installations, such as UTF8, data engine, and so on
#Refer specifically to 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
#If datadir is not specified here, an error will be reported at startup
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
```
//At this point, the installation is complete








- mysql5.7 Binary package installation (highly variable) http://www.apelearn.com/bbs/thread-10105-1-1.html

- mysql5.7 Binary Package Installation

```
1. Download Package 

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

//If the link fails, go to r.aminglinux.com to find the latest download address.

2. decompression 

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. Initialization

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

//Notice that the last line of this step has a hint

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

//The last string is the root password.

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

4. Copy Profile and Startup Script

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

vim /etc/my.cnf //Edit or modify

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   //Edit or modify

basedir=/usr/local/mysql

datadir=/data/mysql

5. Start Services

/etc/init.d/mysqld start

6. Set up root Password

//Log on with an initialization password

/usr/local/mysql/bin/mysql -uroot -p'B*s1i(*,kXwg'  //Set password directly after entering

mysql>set password = password('mypass');   //Be sure to set a new password

//Quit and log in with your new password

//Another case is that you don't know the initialization password

vi /etc/my.cnf

//Add a line below [mysqld]

skip-grant-tables

//Restart / etc/init.d/mysqld restart

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

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

//When you exit, change my.cnf to remove skip-grant-tables you just added

//Restart / etc/init.d/mysqld restart
```

- Now you can use the new password.


Topics: MySQL Linux MariaDB Apache