LNMP架构之MySQL的源码安装

LNMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写。L指Linux,N指Nginx,M一般指MySQL,也可以指MariaDB,P一般指PHP,也可以指Perl或Python。

1.编译安装

 mkdir /usr/local/lnmp
tar zxf mysql-boost-5.7.17.tar.gz

在这里插入图片描述

yum install cmake-2.8.12.2-4.el6.x86_64.rpm  -y
yum install -y gcc gcc-c++ 
yum install -y ncurses-devel
yum install -y bison

添加配置

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_BOOST=boost/boost_1_59_0/

在这里插入图片描述
编译:
make
在这里插入图片描述
安装:
make install

2.配置

注意:硬盘必须大于等于20G

1.添加用户

groupadd -g 27 mysql
useradd -u 27 -g 27 mysql -s /sbin/nologin 
[root@big1 ~]# id mysql
uid=27(mysql) gid=27(mysql) groups=27(mysql)

在这里插入图片描述

2.配置环境变量

 vim ~/.bash_profile
# User specific environment and startup programs

PATH=$PATH:$HOME/bin
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin

source ~/.bash_profile

在这里插入图片描述

3.配置文件

cd support-files/
cp my-default.cnf /etc/my.cnf
vim /etc/my.cnf
# These are commonly set, remove the # and set as required.
basedir = /usr/local/lnmp/mysql
datadir = /usr/local/lnmp/mysql/data
# port = .....
# server_id = .....
#@CNF_SOCKET_LINE@
socket = /usr/local/lnmp/mysql/data/mysql.sock

在这里插入图片描述

chown root.mysql /usr/local/lnmp/mysql/ -R

4.制作启动脚本

cd /usr/local/lnmp/mysql/support-files
 cp mysql.server /etc/init.d/mysqld
cd /etc/init.d/
chmod +x mysqld 
ll
-rwxr-xr-x  1 root root 10916 Apr 21 16:16 mysqld

在这里插入图片描述

5.初始化并启动

mysqld --user=mysql --initialize

初始化后最后会给出初始的root密码
在这里插入图片描述

chown mysql.mysql /usr/local/lnmp/mysql/data/ -R
/etc/init.d/mysqld start

在这里插入图片描述

6.安全初始化

mysql_secure_installation		##首先要复制上面生成的密码,修改成自己需要的密码

Securing the MySQL server deployment.

Enter password for user root: 

The existing password for the user account root has expired. Please set a new password.

New password: 

Re-enter new password: 

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: No
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : 

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 

7.测试

[root@server1 ~]# mysql -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.17 Source distribution

Copyright (c) 2000, 2016, 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> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_43511217/article/details/89684316