Linux下编译安装MySQL安装

博主邮箱www.zzher@foxmail.com   qq:1102471911

在学习生活中,我们经常用到linux下的mysql,但是安装是个比较头疼的问题,我在自己的摸索下,写了这篇文章。本文主要方法是编译安装,当然,方法有很多,你也可以用yum进行安装。。。。

考虑到大家都比较懒,命令都给出了,只需复制执行即可 

编译安装MySQL

准备工作:

1、获得以下所需的源代码包,并存放在/usr/local/src(建议用Xshell远程连接,Xshell使用方法见另一边文章)
  与mysql相关:

  • boost_1_59_0.tar.gz
  • cmake-3.6.2.tar.gz
  • mysql-5.7.16.tar.gz

2、安装cmake前的依赖包的安装
  检查gcc-c++ 、ncurses-devel是否安装,如果没有安装,先用yum进行安装,也可以用编译安装的方法,编译安装的方法在首页有介绍

安装:

1、编译安装cmake工具

1 cd /usr/local/src
2 tar xf cmake-3.6.2.tar.gz
3 cd cmake-3.6.2
4 ./bootstrap --prefix=/usr/local/cmake
5 make
6 make install  #如果前面没有指定安装目录,则默认安装到/usr/local/bin/cmake

 

2、建立mysql组和用户,并将mysql用户添加到mysql组

 

1 groupadd mysql
2 useradd -g mysql mysql
3 创建mysql数据文件存放的目录
4 mkdir /mysqldata
5 chown mysql:mysql /mysqldata
6 chmod o= /mysqldata              #设置其他人没有任何权限

 

3、编译安装mysql(复制后,执行即可)

 

1 cd /usr/local/src
2 tar xf mysql-5.7.16.tar.gz
3 cd mysql-5.7.16
4 /usr/local/cmake/bin/cmake .  -DCMAKE_INSTALL_PREFIX=/usr/local/mysql5.7  -DMYSQL_DATADIR=/mysqldata -DWITH_BOOST=/usr/local/src  
-DSYSCONFDIR=/etc -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_DEBUG=0 -DMYSQL_MAINTAINER_MODE=0 -DWITH_SSL:STRING=bundled -DWITH_ZLIB:STRING=bundled 5 make && make install

 

 

 

4、更改mysql安装目录的属主属组并添加mysql环境变量

 

1 chown -R mysql:mysql /usr/local/mysql5.7
2 vim /etc/profile.d/mysql.sh
3 文件内容是:
4 export PATH=$PATH:/usr/local/mysql/bin
5 执行命令:
6 bash                          #让新的PATH变量生效

 

5、加入服务列表并设置为开机自启

 

1 cd /usr/local/mysql/support-files
2 cp mysql.server  /etc/init.d/mysqld
3 chmod +x /etc/init.d/mysqld
4 chkconfig mysqld on

 

6、修改mysql的配置文件

 1 vim /etc/my.cnf
 2 
 3 [mysql]
 4 socket=/tmp/mysql.sock
 5  
 6 [mysqld]
 7 datadir=/mydata
 8 socket=/tmp/mysql.sock
 9 user=mysql
10 symbolic-links=0
11 
12 [mysqld_safe]
13 log-error=/var/log/mysqld.log
14 pid-file=/mydata/mysqld.pid

 

7、初始化mysql

 

1 mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/mydata
说明:
##“-–initialize”会生成一个随机密码(~/.mysql_secret),而”–initialize-insecure”不会生成密码 ##user表示指定用户 ##basedir表示mysql的安装路径,datadir表示数据库文件存放路径

 

8、启动mysql服务

 

# service mysqld start
查看MySQL服务的进程和端口
# ps -ef | grep mysqld
root     22306     1  0 12:51 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/mydata --pid-file=/mydata/web1.deng.com.pid
mysql    22480 22306 12 12:51 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/mydata --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/mydata/web1.deng.com.pid --socket=/tmp/mysql.sock
# netstat -an | grep :3306
tcp        0      0 :::3306                     :::*                        LISTEN

 

 

9、查看MySQL服务的进程和端口

1 # ps -ef | grep mysqld
2 root     22306     1  0 12:51 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/mydata --pid-file=/mydata/web1.deng.com.pid
3 mysql    22480 22306 12 12:51 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/mydata --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/mydata/web1.deng.com.pid --socket=/tmp/mysql.sock
4 
5 # netstat -an | grep :3306
6 tcp        0      0 :::3306                     :::*                        LISTEN

 

 

10、初始化MySQL数据库的root用户密码

 

 1 # mysql_secure_installation 
 2 
 3 Securing the MySQL server deployment.
 4 
 5 Connecting to MySQL using a blank password.
 6 
 7 VALIDATE PASSWORD PLUGIN can be used to test passwords
 8 and improve security. It checks the strength of password
 9 and allows the users to set only those passwords which are
10 secure enough. Would you like to setup VALIDATE PASSWORD plugin?
11 
12 Press y|Y for Yes, any other key for No: y                  #需要修改密码,所以输入y
13 
14 There are three levels of password validation policy:
15 
16 LOW    Length >= 8
17 MEDIUM Length >= 8, numeric, mixed case, and special characters
18 STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file
19 
20 Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2          #设置密码复杂度为强
21 Please set the password for root here.
22 
23 New password: 
24 
25 Re-enter new password:                                      #输入2次新密码
26 
27 Estimated strength of the password: 100 
28 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
29 By default, a MySQL installation has an anonymous user,
30 allowing anyone to log into MySQL without having to have
31 a user account created for them. This is intended only for
32 testing, and to make the installation go a bit smoother.
33 You should remove them before moving into a production
34 environment.
35 
36 Remove anonymous users? (Press y|Y for Yes, any other key for No) : y   #删除匿名用户
37 Success.
38 
39 
40 Normally, root should only be allowed to connect from
41 'localhost'. This ensures that someone cannot guess at
42 the root password from the network.
43 
44 Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y     #禁止root远程登录
45 
46  ... skipping.
47 By default, MySQL comes with a database named 'test' that
48 anyone can access. This is also intended only for testing,
49 and should be removed before moving into a production
50 environment.
51 
52 
53 Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y  #删除测试数据库
54  - Dropping test database...
55 Success.
56 
57  - Removing privileges on test database...
58 Success.
59 
60 Reloading the privilege tables will ensure that all changes
61 made so far will take effect immediately.
62 
63 Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y  #重新加载权限表
64 Success.
65 
66 All done! 

 

 

 

11、将MySQL数据库的动态链接库共享至系统链接库

 

1 vim /etc/ld.so.conf.d/mysql.conf
2 文件内容是:
3 /usr/local/mysql/lib
4 
5 ldconfig -v           让系统重新读取库文件

 

12、测试登陆MySQL数据库

 1 # mysql -uroot -p
 2 Enter password:             #输入刚才设置的新密码
 3 Welcome to the MySQL monitor.  Commands end with ; or \g.
 4 Your MySQL connection id is 5
 5 Server version: 5.7.14 Source distribution
 6 
 7 Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
 8 
 9 Oracle is a registered trademark of Oracle Corporation and/or its
10 affiliates. Other names may be trademarks of their respective
11 owners.
12 
13 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
14 
15 mysql> show databases;
16 +--------------------+
17 | Database           |
18 +--------------------+
19 | information_schema |
20 | mysql              |
21 | performance_schema |
22 | sys                |
23 +--------------------+
24 4 rows in set (0.00 sec)
25 
26 mysql> exit
27 Bye

 

 

到此,linux下的MySQL安装完毕!做需要的文件在后面网盘自行下载

如有错误请及时指出,谢谢!

CentOS-6.8-x86_64-bin-DVD1.iso

链接:https://pan.baidu.com/s/1hSjlElLDz7F4E2Ese0AMKA
提取码:wsb3


cmake-3.6.2.tar.gz

链接:https://pan.baidu.com/s/1VNENQic4iK9pS0uT94QNHQ 

提取码:rnii
boost_1_59_0.tar.gz

链接:https://pan.baidu.com/s/1GrAEYekiq5t-D4TRQQeptQ
提取码:dviz


mysql-5.7.16.tar.gz

 

 

链接:https://pan.baidu.com/s/1_Gk3P7nUb7D3B3JOCF7w_g
提取码:qktl

 

posted @ 2019-01-08 21:33  DBA_zzher  阅读(255)  评论(0编辑  收藏  举报