MySQL 从5.5开始改用cmake来编译源码,本例为编译源码安装 mysql :


# 添加 Mysql 帐号

useradd mysql -s /sbin/nologin

#创建文件夹

mkdir -p /usr/local/mysql #存放mysql路径

mkdir -p /usr/local/mysqldb #存放数据库文件路径,具体路径可根据需要自行创建

chown mysql:mysql /usr/local/mysqldb #设置访问权限

# 安装编译软件

yum -y install bison gcc gcc-c++ cmake ncurses-devel

wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.15.tar.gz

# 安装 Mysql

1 tar zxvf mysql-5.6.15.tar.gz

2 cd mysql-5.6.15

3 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysqldb -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DMYSQL_USER=mysql -DDEFAULT_COLLATION=utf8_general_ci

4 make -j2

5 make install

# 初始化 Mysql

cd /usr/local/mysql

1 cp ./support-files/my-default.cnf /etc/my.cnf  #复制配置文件,如果存在覆盖即可

2 cp ./support-files/mysql.server /etc/init.d/mysqld      #可用service命令重启

3 chmod 755 /etc/init.d/mysqld                             #权限设定为755

4 chkconfig --level 35 mysqld on                            #增加 mysql 自动启动级别

5 ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysqldb                          #创建系统数据库

6 vi /etc/profile                   #将mysql服务加入到系统变量,在最后一行添加

export PATH=$PATH:/usr/local/mysql/bin

7 vi /etc/rc.d/init.d/mysqld

basedir=/usr/local/mysql     #mysql安装路径

datadir=/usr/local/mysqldb  #mysql数据库存放路径

8 reboot       #重启服务器

9 mysql_secure_installation #设置mysql密码或直接修改密码

mysqladmin -u root -p password "123456"  #设置密码

10 service mysqld restart  #重启服务

mysql安装完成


# 优化 Mysql 配置文件

1 # 以4核cpu 8G内存 的硬件配置来优化参数: vim /etc/my.cnf

2 #

3 # This is for a large system with memory of 1G-2G where the system runs mainly

4 # MySQL.

5 #

6 # MySQL programs look for option files in a set of

7 # locations which depend on the deployment platform.

8 # You can copy this option file to one of those

9 # locations. For information about these locations, see:

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

11 #

12 # In this file, you can use all long options that a program supports.

13 # If you want to know which options a program supports, run the program

14 # with the "--help" option.

15  

16 # The following options will be passed to all MySQL clients

17 [client]

18 #password       = your_password

19 port            = 3306

20 socket          = /tmp/mysql.sock

21  

22 # Here follows entries for some specific programs

23 # The MySQL server

24 [mysqld]

25 port            = 3306

26 socket          = /tmp/mysql.sock

27 skip-external-locking

28 key_buffer_size = 4096M

29 max_allowed_packet = 2M

30 table_open_cache = 1024

31 sort_buffer_size = 2M

32 read_buffer_size = 32M

33 read_rnd_buffer_size = 32M

34 myisam_sort_buffer_size = 128M

35 thread_cache_size = 64

36 query_cache_size = 128M

37 datadir=/usr/local/mysql/data

38 lower_case_table_names = 1

39 skip-name-resolve

40 max_connections = 1024

41 character-set-server = utf8

42 collation-server = utf8_general_ci

43 # Try number of CPU's*2 for thread_concurrency

44 thread_concurrency = 8

45  

46 # Don't listen on a TCP/IP port at all. This can be a security enhancement,

47 # if all processes that need to connect to mysqld run on the same host.

48 # All interaction with mysqld must be made via Unix sockets or named pipes.

49 # Note that using this option without enabling named pipes on Windows

50 # (via the "enable-named-pipe" option) will render mysqld useless!

51 #

52 #skip-networking

53  

54 # Replication Master Server (default)

55 # binary logging is required for replication

56 log-bin=mysql-bin

57 expire_logs_days = 10

58  

59 # required unique id between 1 and 2^32 - 1

60 # defaults to 1 if master-host is not set

61 # but will not function as a master if omitted

62 server-id = 1

63  

64 # Replication Slave (comment out master section to use this)

65 #

66 # To configure this host as a replication slave, you can choose between

67 # two methods :

68 #

69 # 1) Use the CHANGE MASTER TO command (fully described in our manual) -

70 #    the syntax is:

71 #

72 #    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,

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

74 #

75 #    where you replace <host>, <user>, <password> by quoted strings and

76 #    <port> by the master's port number (3306 by default).

77 #

78 #    Example:

79 #

80 #    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,

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

82 #

83 # OR

84 #

85 # 2) Set the variables below. However, in case you choose this method, then

86 #    start replication for the first time (even unsuccessfully, for example

87 #    if you mistyped the password in master-password and the slave fails to

88 #    connect), the slave will create a master.info file, and any later

89 #    change in this file to the variables' values below will be ignored and

90 #    overridden by the content of the master.info file, unless you shutdown

91 #    the slave server, delete master.info and restart the slaver server.

92 #    For that reason, you may want to leave the lines below untouched

93 #    (commented) and instead use CHANGE MASTER TO (see above)

94 #

95 # required unique id between 2 and 2^32 - 1

96 # (and different from the master)

97 # defaults to 2 if master-host is set

98 # but will not function as a slave if omitted

99 #server-id       = 2

100 #

101 # The replication master for this slave - required

102 #master-host     =   <hostname>

103 #

104 # The username the slave will use for authentication when connecting

105 # to the master - required

106 #master-user     =   <username>

107 #

108 # The password the slave will authenticate with when connecting to

109 # the master - required

110 #master-password =   <password>

111 #

112 # The port the master is listening on.

113 # optional - defaults to 3306

114 #master-port     =  <port>

115 #

116 # binary logging - not required for slaves, but recommended

117 #log-bin=mysql-bin

118 #

119 # binary logging format - mixed recommended

120 #binlog_format=mixed

121  

122 # Uncomment the following if you are using InnoDB tables

123 #innodb_data_home_dir = /usr/local/mysql/data

124 #innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend

125 #innodb_log_group_home_dir = /usr/local/mysql/data

126 # You can set .._buffer_pool_size up to 50 - 80 %

127 # of RAM but beware of setting memory usage too high

128 #innodb_buffer_pool_size = 384M

129 #innodb_additional_mem_pool_size = 20M

130 # Set .._log_file_size to 25 % of buffer pool size

131 #innodb_log_file_size = 100M

132 #innodb_log_buffer_size = 8M

133 #innodb_flush_log_at_trx_commit = 1

134 #innodb_lock_wait_timeout = 50

135  

136 [mysqldump]

137 quick

138 max_allowed_packet = 32M

139  

140 [mysql]

141 no-auto-rehash

142 # Remove the next comment character if you are not familiar with SQL

143 #safe-updates

144  

145 [myisamchk]

146 key_buffer_size = 1024M

147 sort_buffer_size = 512M

148 read_buffer = 32M

149 write_buffer = 64M

150  

151 [mysqlhotcopy]

152 interactive-timeout


# 启动 Mysql

1 cd /usr/local/mysql/bin

2 ./mysqld_safe –defaults-file=/etc/my.cnf --user=mysql &

# 应用 Mysql

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

2  

3 mysql> show processlist;                    -- 查看当前正在执行的任务

4 mysql> show variables;                      -- 查看系统变量

5 mysql> show variables like 'max%';          -- 查看max开头的系统变量

6 mysql> show status;                         -- 查看当前系统状态

7 mysql> show status like 'qcache%';          -- 查看与qcache相关的系统状态

8 mysql> show status like 'max%';             -- 查看与max相关的系统状态

9 mysql> show master status;                  -- 查看主从关系中主服务器状态

10 mysql> show slave status;                   -- 查看主从关系中从服务器状态