《Mysql入门centos编译安装mysql 5.6及安装多个mysql实例详解》要点:
本文介绍了Mysql入门centos编译安装mysql 5.6及安装多个mysql实例详解,希望对您有用。如果有疑问,可以联系我们。
MYSQL入门--1.为mysql新建组和用户
MYSQL入门
# useradd -M -s /sbin/nologin mysql
MYSQL入门--2.安装需要的库,编译器
MYSQL入门
# yum install ncurses-devel openssl-devel cmake -y
MYSQL入门--3.解压
MYSQL入门
# tar zxvf mysql-5.6.35.tar.gz
# cd mysql-5.6.35
MYSQL入门--4.编译安装
MYSQL入门
# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_USER=mysql \
-DWITH_DEBUG=0 \
-DWITH_SSL=system
# make
# make install
MYSQL入门--5.拷贝模版,作为配置文件
MYSQL入门
# cp support-files/my-default.cnf /etc/my.cnf
MYSQL入门--6.设置mysql权限
MYSQL入门
# chown -R mysql.mysql /usr/local/mysql/
MYSQL入门--7.初始化mysql数据库
MYSQL入门
# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
# chown -R root /usr/local/mysql/
# chown -R mysql /usr/local/mysql/data/
MYSQL入门--8.设置mysql开机自启动
MYSQL入门
# cp support-files/mysql.server /etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld
# chkconfig mysqld on
MYSQL入门--9.测试并运行mysql
MYSQL入门
#service mysqld start
MYSQL入门--10.修改mysql管理员密码
MYSQL入门
#/usr/local/mysql/bin/mysqladmin -u root password '要设置的密码'
MYSQL入门--11.使用用户登录mysql
MYSQL入门
# /usr/local/mysql/bin/mysql -u root -p
MYSQL入门--12.加入环境变量
MYSQL入门
# echo 'PATH=/usr/local/mysql/bin/:$PATH' >>/etc/profile
# source /etc/profile
MYSQL入门 CentOS 6.5最小化编译安装mysql 5.5.35配置多实例
MYSQL入门1、关闭防火墙
MYSQL入门
1234567 [root@mysql ~]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@mysql ~]# chkconfig iptables off
[root@mysql ~]# chkconfig iptables --list
iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off
MYSQL入门2、关闭selinux
MYSQL入门
12 [root@mysql ~]# setenforce 0
[root@mysql ~]# vim /etc/sysconfig/selinux
MYSQL入门修改下面这一行;
MYSQL入门
SELINUX=disabled
12 [root@mysql ~]# getenforce
Permissive
MYSQL入门3、安装mysql依赖包及编译工具;
MYSQL入门
1234 [root@mysql ~]# yum install libaio-devel -y
[root@mysql ~]# yum install -y ncurses-devel
[root@mysql ~]# yum install -y gcc gcc-c++
[root@mysql ~]# yum install -y cmake
MYSQL入门4、安装前准备;
MYSQL入门4.1、安装路径:
MYSQL入门
1 [root@mysql ~]# mkdir /usr/local/mysql
MYSQL入门4.2、数据库路径:
MYSQL入门
1 [root@mysql ~]# mkdir /data/mysql -p
MYSQL入门4.3、创建用户和用户组
MYSQL入门
12 [root@mysql ~]# groupadd mysql
[root@mysql ~]# useradd -r -g mysql -s /bin/false mysql
MYSQL入门4.4、赋予数据存放目录权限
MYSQL入门
1 [root@mysql ~]# chown mysql:mysql -R /data/mysql
MYSQL入门5、编译安装mysql 5.5.35
MYSQL入门
1234567 [root@mysql ~]# yum install -y lrzsz
root@mysql ~]# mkdir /package
[root@mysql ~]# cd /package/
[root@mysql package]# tar xf mysql-5.5.32.tar.gz
[root@mysql package]# cd mysql-5.5.32
[root@mysql mysql-5.5.32]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql/ -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306
[root@mysql mysql-5.5.32]# make && make install
MYSQL入门6、创建多实例数据库文件存放位置;
MYSQL入门
12345678 [root@mysql ~]# mkdir -p /data/{3306,3307}/data
[root@mysql ~]# tree /data
/data
|-- 3306
| `-- data
`-- 3307
`-- data
4 directories, 0 files
MYSQL入门7、修改配置文件(my.cnf)如下行,分别放入3306、3307目录当中;
MYSQL入门
123456789 [root@mysql 3306]# vim my.cnf
[client]
port = 3306
socket = /data/3306/mysql.sock
[mysqld]
port = 3306
socket = /data/3306/mysql.sock
datadir = /data/3306
server-id = 3306
MYSQL入门8、初始化数据库;
MYSQL入门注意:初始化数据库时需要指定不同的数据目录
MYSQL入门
123 [root@mysql mysql-5.5.32]# cd /usr/local/mysql/
[root@mysql mysql]# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306
[root@mysql mysql]# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/3307
MYSQL入门9、启动多实例,启动脚本可以加入到开机自启动文件中.
MYSQL入门
12 [root@mysql mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/3306/my.cnf 2>&1 >/dev/null &
[root@mysql mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/3307/my.cnf 2>&1 >/dev/null &
MYSQL入门9.1、查看端口;
MYSQL入门
12345678 [root@mysql mysql]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 11621/mysqld
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1266/sshd
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 11338/mysqld
tcp 0 0 :::22 :::* LISTEN 1266/sshd
udp 0 0 0.0.0.0:68 0.0.0.0:* 969/dhclient
MYSQL入门10、登录多实例数据库
MYSQL入门
12 [root@mysql mysql]# /usr/local/mysql/bin/mysql -u root -p -P 3306 -S /data/3306/mysql.sock
[root@mysql mysql]# /usr/local/mysql/bin/mysql -u root -p -P 3307 -S /data/3307/mysql.sock
MYSQL入门11、关闭mysql多实例方式
MYSQL入门
12 [root@mysql mysql]# /usr/local/mysql/bin/mysqladmin -u root -p -P 3306 -S /data/3306/mysql.sock shutdown
[root@mysql mysql]# /usr/local/mysql/bin/mysqladmin -u root -p -P 3307 -S /data/3307/mysql.sock shutdown
cat /etc/my.cnf
[mysqld1]
datadir=/data/mysql
socket=/tmp/mysql.sock
user=mysql
symbolic-links=0
skip-name-resolve
server-id=1221
max_connections = 2000
binlog-ignore-db=mysql
binlog-ignore-db=test
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
innodb_buffer_pool_size = 2G
innodb_additional_mem_pool=16M
innodb_log_file_size=256M
innodb_flush_log_at_trx_commit=2
character_set_server=utf8
collation_server = utf8_general_ci
replicate_ignore_db = mysql
slave-skip-errors=all
relay_log=/data/mysql/
[mysqld2]
port=3307
server-id=1222
log-error=/tmp/mysqld2.log
datadir=/data/mysql_live
socket=/tmp/mysql2.sock
user=mysql
symbolic-links=0
skip-name-resolve
character_set_server=utf8
collation_server = utf8_general_ci
max-connections=500
default-storage-engine=INNODB
innodb_file_per_table
log-bin=mysql-bin
relay-log-info-repository=TABLE
master-info-repository=TABLE
expire_logs_days=10
binlog_format=ROW
transaction-isolation=READ-COMMITTED
binlog-ignore-db=mysql
binlog-ignore-db=test
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
slow_query_log=TRUE
slow_query_log_file=/tmp/mysqld_slow_query2.log
long_query_time=3
replicate_ignore_db = mysql
slave-skip-errors=all
[mysqld3]
server-id=1223
port=3308
log-error=/tmp/mysqld3.log
datadir=/data/mysql
socket=/tmp/mysql3.sock
user=mysql
symbolic-links=0
skip-name-resolve
character_set_server=utf8
collation_server = utf8_general_ci
max-connections=500
default-storage-engine=INNODB
innodb_file_per_table
log-bin=mysql-bin
relay-log-info-repository=TABLE
master-info-repository=TABLE
expire_logs_days=10
binlog_format=ROW
transaction-isolation=READ-COMMITTED
binlog-ignore-db=mysql
binlog-ignore-db=test
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
slow_query_log=TRUE
slow_query_log_file=/tmp/mysqld_slow_query3.log
long_query_time=3
replicate_ignore_db = mysql
slave-skip-errors=all
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/data/mysql/mysqld.pid
转载请注明本页网址:
http://www.vephp.com/jiaocheng/1181.html