Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1208928
  • 博文数量: 259
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 2518
  • 用 户 组: 普通用户
  • 注册时间: 2012-10-13 16:12
个人简介

科技改变世界,技术改变人生。

文章分类

全部博文(259)

分类: Mysql/postgreSQL

2015-09-24 18:35:59

需求在一台服务器上部署两台MYSQL库,默认是3306端口,第二库使用3307端口

netstat -tlnap | grep mysql
ps -ef| grep mysql

部署前:
[root@server01 mysql3307]# ps -ef|grep mysql
root      58995  49022  0 16:55 pts/0    00:00:00 grep mysql
root     199196      1  0 Apr24 ?        00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/server01.100.cloud.pid
mysql    199545 199196  0 Apr24 ?        02:06:32 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/server01.err --pid-file=/var/lib/mysql/server01.pid --socket=/var/lib/mysql/mysql.sock --port=3306




部署后:
[root@server01 mysql3307]# ps -ef|grep mysql
root      59128      1  0 17:04 pts/0    00:00:00 /bin/sh /usr/local/mysql3307/bin/mysqld_safe --datadir=/usr/local/mysq3307/data --pid-file=/usr/local/mysql3307/data/server01.pid

mysql     59647  59128  0 17:04 pts/0    00:00:00 /usr/local/mysql3307/bin/mysqld --basedir=/usr/local/mysql3307 --datadir=/usr/local/mysql3307/data --plugin-dir=/usr/local/mysql3307/lib/plugin --user=mysql --log-error=/usr/local/mysql3307/data/server01.100.cloud.err --pid-file=/usr/local/mysql3307/data/server01.100.cloud.pid --socket=/usr/local/mysql3307/mysq3307.sock --port=3307

root      59675  49022  0 17:05 pts/0    00:00:00 grep mysql
root     199196      1  0 Apr24 ?        00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/server01.100.cloud.pid

mysql    199545 199196  0 Apr24 ?        02:06:32 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/server01.err --pid-file=/var/lib/mysql/server01.pid --socket=/var/lib/mysql/mysql.sock --port=3306



下载地址:
/>
tar -zxvf mysql-5.5.45.tar.gz
cd /root/mysql-5.5.45
mkdir /usr/local/mysql3307
mkdir /usr/local/mysql3307/etc
mkdir /usr/local/mysql3307/date
yum install -y gcc gcc-c++ ncurses-devel bison cmake

mysql5.5 用的cmake编译,需要安装cmake

进入解压目录,开始cmake
          
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql3307 -DMYSQL_UNIX_ADDR=/usr/local/mysql3307/mysql3307.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/usr/local/mysql3307 -DMYSQL_TCP_PORT=3307 -DENABLE_DOWNLOADS=1

make && make install


进入mysql2安装目录,设置目录权限
[root@localhost mysql-5.5.45]# cd /usr/local/mysql3307
[root@localhost mysql2]# chown -R mysql:mysql .
[root@localhost mysql2]# chown -R mysql:mysql data


复制mysql服务启动脚本及加入PATH路径
[root@localhost mysql2]# cp support-files/mysql.server /etc/init.d/mysql3307
chmod +x /etc/init.d/mysql3307
chkconfig --add mysql3307
chkconfig mysql3307 on

vi /etc/init.d/mysql3307
#conf=/etc/my.cnf
conf=/usr/local/mysql3307/etc/my.cnf

分别初始化数据库脚本(在编译目录执行下)

scripts/mysql_install_db --basedir=/usr/local/mysql/ --user=mysql
第二个库:
/usr/local/mysql3307/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql3307 --datadir=/usr/local/mysql3307/data


修改从库配置文件



cp usr/local/mysql/support-files/my-medium.cnf /usr/local/mysql/etc/my.cnf
cp /usr/local/mysql3307/support-files/my-medium.cnf /usr/local/mysql3307/etc/my.cnf


配置开启自动:

cp /usr/local/software/mysql-6.0.11-alpha/support-files/mysql.server /etc/init.d/mysql
cp /usr/local/mysql3307/support-files/mysql.server  /etc/init.d/mysql3307

修改/etc/init.d/mysql3307中basedir与datadir为即可

basedir=/usr/local/mysql3307
datadir=/usr/local/mysql3307/data



修改
/usr/local/mysql3307/etc/my.cnf
[mysqld]
datadir=/usr/local/mysql3307/data
socket=/usr/local/mysql3307/mysql3307.sock

[mysqld_safe]
log-error=/var/log/mysqld3307.log
pid-file=/usr/local/mysql3307/mysqld3307.pid



启动3307数据库
/usr/local/mysql3307/bin/mysqld_safe --datadir=/usr/local/mysql3307/data --socket=/usr/local/mysql3307/mysql3307.sock \
--pid-file=/var/run/mysqld/mysqld3307.pid \
--log-error=/var/log/mysqld3307.log \
--basedir=/usr/local/mysql3307 --user=mysql --port=3307 &

启停:
service mysql3307 start
service mysql3307 stop


登录:

mysql -uroot --socket=/usr/local/mysql3307/mysql3307.sock --port=3307 -p


修改root密码
mysql> use mysql;
mysql> update user set password=password('root123#@!') where user='root';
mysql> FLUSH PRIVILEGES;


停止mysql 3307

[root@localhost etc]# mysqladmin -uroot --socket=/usr/local/mysql3307/mysql3307.sock --port=3307 -p shutdown


新建用户
mysql> create database fids;
mysql> create user "fids" identified by "fids123#@!";
mysql> grant all privileges on fids.* to fids;
mysql> flush privileges;

mysql> grant select on fids.* to fids@localhost;
mysql> grant select on fids.* to fids@172.0.0.1;

use mysql;
update user set password=password('fids123#@!') where user='fids';
flush privileges;


允许用户远程登录
mysql>update user set host = '%' where user = 'root';
root对应的host成了%,表示可以任意IP地址登录了.
mysql>flush privileges;

查看当前用户
select user();

查看用户权限
SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;
查看数据库中具体某个用户的权限
mysql> show grants for 'fids'@'%';


参考:
http://blog.csdn.net/swengineer/article/details/6239711
http://blog.chinaunix.net/uid-9881170-id-2518801.html
http://blog.chinaunix.net/uid-21505614-id-302263.html
阅读(5831) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~