Lnmp安装之mysql5.6

2016-12-19 10:48:46来源:oschina作者:QIANG008人点击

第七城市

1. 安装mysql所需依赖包:如果你是根据我的教程来安装过了nginx1.11.3的话则不需要做这一步操作。



1


yuminstallvimvim-enhancedwgetzipunziptelnetntsysvcompat*apr*nasm*gccgcc*gcc-c++ntpmakeimakecmakeautomakeautoconfzlibzlib-develglibcglibc-develglib2libxmlglib2-devellibxml2libxml2-develbzip2bzip2-devellibXpmlibXpm-devellibidnlibidn-devellibtoollibtool-ltdl-devel*libmcryptlibmcrypt-devellibevent-devellibmcrypt*curlcurl-develperlperl-Net-SSLeaypcrepcre-develncursesncurses-developensslopenssl-developenldapopenldap-developenldap-clientsopenldap-serverskrb5krb5-devele2fsprogse2fsprogs-devellibjpeglibpnglibjpeg-devellibjpeg-6blibjpeg-devel-6blibpng-devellibtiff-develfreetypefreetype-develfontconfig-develgdgd-develkernelscreensysstatflexbisonnss_ldappam-develcompat-libstdc++-33


2. 安装mysql



1

2

3

4

5

6

7

8

9

10

11

12

13

14

15


mysql-5.6.23.tar.gz

tar-zxvfmysql-5.6.23.tar.gz

cdmysql-5.6.23

cmake/

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql/

-DMYSQL_DATADIR=/home/mysql/data/

-DEXTRA_CHARSETS=all/

-DDEFAULT_CHARSET=utf8/

-DDEFAULT_COLLATION=utf8_general_ci/

-DWITH_READLINE=1/

-DWITH_SSL=system/

-DWITH_ZLIB=system/

-DWITH_EMBEDDED_SERVER=1/

-DENABLED_LOCAL_INFILE=1

make&&makeinstall


3.创建权限



1

2


groupaddmysql

useradd-s/sbin/nologin-M-gmysqlmysql


4. 创建相应目录



1

2

3

4


mkdir-p/home/mysql/logs

mkdir-p/home/mysql/data

chown-Rmysql:mysql/home/mysql/logs

chown-Rmysql:mysql/home/mysql/data


5. 配置 vim /etc/my.cnf (注意红色部分的目录,要跟上面创建的一样)



1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153


#ExampleMySQLconfigfileformediumsystems.

#

#Thisisforasystemwithlittlememory(32M-64M)whereMySQLplays

#animportantpart,orsystemsupto128MwhereMySQLisusedtogetherwith

#otherprograms(suchasawebserver)

#

#MySQLprogramslookforoptionfilesinasetof

#locationswhichdependonthedeploymentplatform.

#Youcancopythisoptionfiletooneofthose

#locations.Forinformationabouttheselocations,see:

#http://dev.mysql.com/doc/mysql/en/option-files.html

#

#Inthisfile,youcanusealllongoptionsthataprogramsupports.

#Ifyouwanttoknowwhichoptionsaprogramsupports,runtheprogram

#withthe"--help"option.

#ThefollowingoptionswillbepassedtoallMySQLclients

[client]

#password=your_password

port=3306

socket=/tmp/mysql.sock

[mysqld_safe]

log-error=/home/mysql/logs/mysqld.log

#Herefollowsentriesforsomespecificprograms

#TheMySQLserver

[mysqld]

port=3306

socket=/tmp/mysql.sock

datadir=/home/mysql/data

skip-external-locking

max_connections=1000

key_buffer_size=16M

max_allowed_packet=1M

table_open_cache=64

sort_buffer_size=512K

net_buffer_length=8K

read_buffer_size=256K

read_rnd_buffer_size=512K

myisam_sort_buffer_size=8M

explicit_defaults_for_timestamp=true

innodb_force_recovery=1

#Don'tlistenonaTCP/IPportatall.Thiscanbeasecurityenhancement,

#ifallprocessesthatneedtoconnecttomysqldrunonthesamehost.

#AllinteractionwithmysqldmustbemadeviaUnixsocketsornamedpipes.

#NotethatusingthisoptionwithoutenablingnamedpipesonWindows

#(viathe"enable-named-pipe"option)willrendermysqlduseless!

#

#skip-networking

#ReplicationMasterServer(default)

#binaryloggingisrequiredforreplication

log-bin=mysql-bin

#binaryloggingformat-mixedrecommended

binlog_format=mixed

#requireduniqueidbetween1and2^32-1

#defaultsto1ifmaster-hostisnotset

#butwillnotfunctionasamasterifomitted

server-id=1

#ReplicationSlave(commentoutmastersectiontousethis)

#

#Toconfigurethishostasareplicationslave,youcanchoosebetween

#twomethods:

#

#1)UsetheCHANGEMASTERTOcommand(fullydescribedinourmanual)-

#thesyntaxis:

#

#CHANGEMASTERTOMASTER_HOST=<host>,MASTER_PORT=<port>,

#MASTER_USER=<user>,MASTER_PASSWORD=<password>;

#

#whereyoureplace<host>,<user>,<password>byquotedstringsand

#<port>bythemaster'sportnumber(3306bydefault).

#

#Example:

#

#CHANGEMASTERTOMASTER_HOST='125.564.12.1',MASTER_PORT=3306,

#MASTER_USER='joe',MASTER_PASSWORD='secret';

#

#OR

#

#2)Setthevariablesbelow.However,incaseyouchoosethismethod,then

#startreplicationforthefirsttime(evenunsuccessfully,forexample

#ifyoumistypedthepasswordinmaster-passwordandtheslavefailsto

#connect),theslavewillcreateamaster.infofile,andanylater

#changeinthisfiletothevariables'valuesbelowwillbeignoredand

#overriddenbythecontentofthemaster.infofile,unlessyoushutdown

#theslaveserver,deletemaster.infoandrestarttheslaverserver.

#Forthatreason,youmaywanttoleavethelinesbelowuntouched

#(commented)andinsteaduseCHANGEMASTERTO(seeabove)

#

#requireduniqueidbetween2and2^32-1

#(anddifferentfromthemaster)

#defaultsto2ifmaster-hostisset

#butwillnotfunctionasaslaveifomitted

#server-id=2

#

#Thereplicationmasterforthisslave-required

#master-host=<hostname>

#

#Theusernametheslavewilluseforauthenticationwhenconnecting

#tothemaster-required

#master-user=<username>

#

#Thepasswordtheslavewillauthenticatewithwhenconnectingto

#themaster-required

#master-password=<password>

#

#Theportthemasterislisteningon.

#optional-defaultsto3306

#master-port=<port>

#

#binarylogging-notrequiredforslaves,butrecommended

#log-bin=mysql-bin

#UncommentthefollowingifyouareusingInnoDBtables

innodb_data_home_dir=/home/mysql/data

innodb_data_file_path=ibdata1:10M:autoextend

innodb_log_group_home_dir=/home/mysql/data

#Youcanset.._buffer_pool_sizeupto50-80%

#ofRAMbutbewareofsettingmemoryusagetoohigh

innodb_buffer_pool_size=16M

innodb_additional_mem_pool_size=2M

#Set.._log_file_sizeto25%ofbufferpoolsize

innodb_log_file_size=5M

innodb_log_buffer_size=8M

innodb_flush_log_at_trx_commit=1

innodb_lock_wait_timeout=50

[mysqldump]

quick

max_allowed_packet=16M

[mysql]

no-auto-rehash

#RemovethenextcommentcharacterifyouarenotfamiliarwithSQL

#safe-updates

[myisamchk]

key_buffer_size=20M

sort_buffer_size=20M

read_buffer=2M

write_buffer=2M

[mysqlhotcopy]

interactive-timeout

expire_logs_days=10


6.生成新的mysql授权表:



1


/usr/local/mysql/scripts/mysql_install_db--defaults-file=/etc/my.cnf--basedir=/usr/local/mysql--datadir=/home/mysql/data--user=mysql


7. 添加加载mysql库文件的路径:



1

2

3

4

5

6


cat>/etc/ld.so.conf.d/mysql-x86_64.conf<<EOF

/usr/local/mysql/lib

/usr/lib64/mysql

EOF

cp/etc/ld.so.conf.d/mysql-x86_64.conf/etc/ld.so.conf.d/mysql.conf

ldconfig


8. 链接mysql可执行文件:



1

2

3

4

5

6

7


ln-s/usr/local/mysql/lib/mysql/usr/lib64/mysql

ln-s/usr/local/mysql/include/mysql/usr/include/mysql

ln-s/usr/local/mysql/bin/mysql/usr/bin/mysql

ln-s/usr/local/mysql/bin/mysqldump/usr/bin/mysqldump

ln-s/usr/local/mysql/bin/myisamchk/usr/bin/myisamchk

ln-s/usr/local/mysql/bin/mysqld_safe/usr/bin/mysqld_safe

ln-s/usr/local/mysql/bin/mysqladmin/usr/bin/mysqladmin


9. 添加mysqld系统服务:



1

2

3

4

5


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

chmod+x/etc/init.d/mysqld

chkconfig--addmysqld

chkconfig--level2345mysqldon

chkconfig--list|grepmysqld


10. 启动mysql服务:



1

2

3


servicemysqldstart

ps-aux|grepmysqld

netstat-anptu|grep:3306


11.登录并修改mysql的root密码:



1

2

3

4

5

6

7

8

9

10

11

12


mysql-uroot-p

(第一次登录root密码为空)

usemysql;

updateusersetpassword=PASSWORD('123456')whereuser='root';

deletefromuserwherenot(user='root');

deletefromuserwhereuser='root'andpassword='';

deletefromuserwhereHost='localhost.localdomain';

deletefromuserwhereHost='::1';

grantallprivilegeson*.*toroot@"%"identifiedby"root";

updatemysql.usersetGrant_priv='Y'whereHost='%';

flushprivileges;

exit;


12.刷新MySQL连接主机数量:



1

2


mysqladmin-uroot-pflush-hosts

#输入mysql的root帐号新密码


13.防火墙开启3306端口:



1


iptables-AINPUT-ptcp--dport3306-jACCEPT

第七城市

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台