系统版本:
[root@master ~]# lsb_release -a
LSB Version: :core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-ia32:graphics-4.0-
noarch:printing-4.0-amd64:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 5.8 (Final)
Release: 5.8
Codename: Final
[root@master ~]# uname -a
Linux master 2.6.18-308.el5 #1 SMP Tue Feb 21 20:06:06 EST 2012 x86_64 x86_64 x86_64 GNU/Linux
安装所需要库程序:
[root@master ~]# yum -y remove mysql-server mysql mysql-devel
[root@master ~]# yum -y install gcc gcc-c++ ncurses-devel libtool openssl-devel cmake
[root@master ~]# groupadd mysql #创建用户组
[root@master ~]# useradd -r -g mysql mysql #创建用户并加入组
[root@master ~]# mkdir /usr/local/mysql #创建mysql安装目录
[root@master ~]# mkdir /opt/mysql/data #创建数据存放目录
#设置安装和数据目录所属用户与组
[root@master ~]# chown -R mysql /usr/local/mysql
[root@master ~]# chgrp -R mysql /usr/local/mysql
[root@master ~]# chown -R mysql:mysql /opt/mysql/data
#开始安装数据库
下载安装包:mysql-5.5.37.tar.gz 5lbde3fcscar http://115.com/lb/5lbde3fcscar
[root@master ~]# cd ~
[root@master ~]# tar zxvf ~/mysql-5.5.37.tar.gz
[root@master ~]# mv mysql-5.5.37 /usr/local/src/
[root@master ~]# cd /usr/local/src/mysql-5.5.37
[root@master ~]# cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/opt/mysql/data/ \
-DMYSQL_UNIX_ADDR=/opt/mysql/data/mysqld.sock \
-DSYSCONFDIR=/etc \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \
-DWITH_DEBUG=0 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_USER=mysql
[root@master ~]# make && make install
[root@master ~]# cp support-files/my-medium.cnf /etc/my.cnf
[root@master ~]# cp support-files/mysql.server /etc/init.d/mysqld
[root@master ~]# chmod 755 /etc/init.d/mysqld
[root@master ~]# bash scripts/mysql_install_db --user=mysql
[root@master ~]# export PATH=/usr/local/mysql/bin:$PATH
[root@master ~]# echo "PATH=/usr/local/mysql/bin:$PATH" >>/ect/profile
[root@master ~]# bash scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/opt/mysql/data/
[root@master ~]# /etc/init.d/mysqld start
[root@master ~]# mysqladmin -uroot password "123456"
[root@master ~]# pkill mysql
[root@master ~]# mysqld_safe --user=mysql &
[root@master ~]# mysql -u root -p
mysql>use mysql ;
mysql>update user set password=PASSWORD("root") where user=‘root‘;
mysql>flush privileges;
查看端口
netstat -anp |grep mysqld
查看进程
ps -ef |grep mysql
关闭进程
pkill mysql
使用服务器启动和关闭
service mysqld restart
service mysqld start
service mysqld stop
########################################################
mysql多实例的配置和管理
########################################################
[root@master ~]# mkdir -p /opt/mysql/data2
[root@master ~]# mkdir -p /opt/mysql/data3
[root@master ~]# chown -R mysql:mysql /opt/mysql/data2
[root@master ~]# chown -R mysql:mysql /opt/mysql/data3
---------------------------------------------------------------------
[root@master ~]# cat /etc/my.cnf
[client]
#password = your_password
port = 3306
socket = /opt/mysql/data/mysqld.sock
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user = test
password = test
[mysqld3306]
port = 3306
socket = /tmp/mysqld3306.sock
pid-file = /tmp/mysql3306.pid
skip-external-locking
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
basedir = /usr/local/mysql/
datadir = /opt/mysql/data
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
[mysqld3307]
port = 3307
socket = /tmp/mysqld3307.sock
pid-file = /tmp/mysql3307.pid
skip-external-locking
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
basedir = /usr/local/mysql/
datadir = /opt/mysql/data2
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
[mysqld3308]
port = 3308
socket = /tmp/mysqld3308.sock
pid-file = /tmp/mysql3308.pid
skip-external-locking
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
basedir = /usr/local/mysql/
datadir = /opt/mysql/data3
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
----------------------------------------------------------------------------
[root@master ~]# cd /usr/local/src/mysql-5.5.37
初始化:
[root@master mysql-5.5.37]# bash scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/opt/mysql/data2 --
user=mysql
[root@master mysql-5.5.37]# bash scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/opt/mysql/data3 --
user=mysql
启动多实例启动:
[root@master mysql-5.5.37]# mysqld_multi --defaults-file=/etc/my.cnf start 3306
[root@master mysql-5.5.37]# mysqld_multi --defaults-file=/etc/my.cnf start 3307
[root@master mysql-5.5.37]# mysqld_multi --defaults-file=/etc/my.cnf start 3308
[root@master mysql-5.5.37]# mysqld_multi --defaults-file=/etc/my.cnf start 3306-3308
登录数据库:
[root@master mysql-5.5.37]# mysql -S /opt/mysql/data/mysqld3306.sock -uroot -p123456
[root@master mysql-5.5.37]# mysql -S /opt/mysql/data/mysqld3307.sock
[root@master mysql-5.5.37]# mysql -S /opt/mysql/data/mysqld3308.sock
设置管理用户test
[root@localhost tmp]# mysqld_multi --defaults-file=/etc/my.cnf start 3308
[root@localhost tmp]# ps -ef |grep mysql
[root@localhost tmp]# mysql -S /tmp/mysqld3308.sock
mysql> show grants for root@localhost;
+---------------------------------------------------------------------+
| Grants for root@localhost |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘localhost‘ WITH GRANT OPTION |
| GRANT PROXY ON ‘‘@‘‘ TO ‘root‘@‘localhost‘ WITH GRANT OPTION |
+---------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> grant shutdown on *.* to test@localhost identified by "test" with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
[root@master mysql-5.5.37]# mysqld_multi --defaults-file=/etc/my.cnf stop 3308|3306|3307 (关闭需要使用管理帐号test)
#########################################################
源代码配置选项说明:
//mysql安装的主目录,5.5.8版本默认为/usr/local/mysql,所以可以不添加
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
//mysql数据保存的路径,自定义
-DMYSQL_DATADIR=/home/system_username/mysql/mysqldata
//mysql配置文件地址------The default my.cnf option file directory
-DSYSCONFDIR=/etc
//Compile storage engine xxx statically into server
/*Storage engines are built as plugins. You can build a plugin as a static module (compiled into the server)
*or a dynamic module (built as a dynamic library that must be installed into the server using the INSTALL
*PLUGIN statement or the --plugin-load option before it can be used). Some plugins might not support static
*or dynamic building.
*/
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_FEDERATED_STORAGE_ENGINE=1
-DWITH_PARTITION_STORAGE_ENGINE=1
//Unix socket file
/*
*The Unix socket file path on which the server listens for socket connections. This must be an absolute path
*name. The default is /tmp/mysql.sock
*/
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock
//数据库服务器TCP/IP连接的监听端口,默认为3306
-DMYSQL_TCP_PORT=3306
//Whether to enable LOCAL capability in the client library for LOAD DATA INFILE
//默认为关闭,这里开启
-DENABLED_LOCAL_INFILE=1
//数据库编码设置
-DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8-general_ci
本文出自 “林子” 博客,请务必保留此出处http://1606496.blog.51cto.com/1596496/1386661