2018-10-26 20:28:22 linzhanwu 阅读数 2239

centos安装多个mysql

  1. 到mysql官网下载的linux包 : 选择linux-Generic(centos)我下载的是 mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

  2. 解压到/data/soft/ 下面, 更名mysql(ps:根据自己习惯设置)
    #tar -xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
    #mv mysql-5.7.24-linux-glibc2.12-x86_64 /data/soft/mysql

  3. 创建文件
    在mysql文件夹下面创建data/ 文件夹(保存数据库数据,也可以放在其他的位置)
    在mysql文件夹下面创建tmp/ 文件夹
    创建mysql数据库my-default.cnf配置文件(Ps:文件可以自己命名,相关的配置也根据自己设置的文件名),(单机多数据库必须创建, 并配置相应的内容):ps配置内容中包含的目录需要手动创建,否则会提示找不相应的目录

[client]
socket=/data/soft/mysql/mysql.sock

[mysqld]
basedir=/data/soft/mysql
datadir=/data/soft/mysql/data
port = 3307
socket=/data/soft/mysql/mysql.sock

[mysql]
socket=/data/soft/mysql/mysql.sock

[mysqldump]
socket=/data/soft/mysql/mysql.sock

[mysqladmin]
socket=/data/soft/mysql/mysql.sock

symbolic-links=0

log-error=/data/soft/mysql/log/mysqld.log
pid-file=/data/soft/mysql/mysqld.pid
  1. 改变文件夹权限
    创建mysql用户和用户组:
     #groupadd mysql     //创建用户组
      #useradd mysql -g mysql       //创建mysql用户,并添加到mysql用户组
      #chown -R mysql:mysql mysql    //改变mysql目录的所属用户和组
      #chmod -R 755 mysql                   //修改mysql目录权限
  1. 安装编译依赖包
#yum -y install make gcc-c++ cmake bison-devel ncurses-devellibaio libaio-devel
  1. 初始化数据库
指定配置文件初始化(ps:会产生mysql随机登录密码):
        #/data/soft/mysql/bin/mysqld --defaults-file=/data/soft//mysql/my-default.cnf --initialize --user=mysql
        #/data/soft/mysql/bin/mysql_ssl_rsa_setup --defaults-file=/data/soft/mysql/my-default.cnf
  1. 启动数据库
前台启动:
        #/data/soft/mysql/bin/mysqld_safe --defaults-file=/data/soft/mysql/my-default.cnf  --user=mysql
    服务启动:
        #/data/soft/mysql/support-files/mysql.server start
  1. 登录更改密码
  #/data/soft/mysql/bin/mysql --socket=/data/soft/mysql/mysql.sock --port==3307 -u root -p

没有随机密码可以执行#grep “password” /data/soft/mysql/log/mysqld.log
可以看到 root@localhost: t7k3QotlqJ;4
这个后面的就是随机的密码。
z在这里插入图片描述
进入直接修改密码

mysql>alter user 'root'@'localhost' identified by '123456';
mysql>use mysql;
msyql>update user set user.Host='%' where user.User='root';
mysql>flush privileges;
mysql>quit
  1. 修改mysql启动脚本(ps:请确保下面参数配置准确,否则会报错Starting MySQL. ERROR! The server quit without updating PID file (/data/soft/mysql/data/localhost.localdomain.pid).

    我们需要修改mysql启动的配置文件 /data/soft/mysql/support-files/mysql.server,
    用vi 编辑这个文件,首先在内容中找到下面内容,默认为空,填上相应的路径与my-default.cnf配置相关路径一致,并在最后就上my-default.cnf这个配置文件的路径。
改变前
basedir=
datadir=

改变后
basedir=/data/soft/mysql
datadir=/data/soft/mysql/data
conf=/data/soft/mysql/my-default.cnf

接着找到extra_args,在相关位置添加extra_args=" -c $conf"

#改变前
extra_args=""
if test -r "$basedir/my.cnf"
then
  extra_args="-e $basedir/my.cnf"
fi
#改变后
extra_args=""
if test -r "$basedir/my.cnf"
then
  extra_args="-e $basedir/my.cnf"
fi
extra_args=" -c $conf"

最后修改mysqld_safe的启动参数,找到bindir/mysqldsafedatadir="bindir/mysqld_safe --datadir="datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null &

#改变前
$bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null &
#改变后
$bindir/mysqld_safe --defaults-file="$conf" --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null &

到了这里参数就修改完成了。
10. mysql服务开机自启配置
将/data/soft/mysql/support-files/mysql.server复制到/etc/init.d目录下并改名,名字可以自己起。
#mv /data/soft/mysql/support-files/mysql.server /etc/init.d/mysql2
赋予执行权限

chmod +x /etc/init.d/mysql2

添加服务

chkconfig --add mysql2

显示服务列表

chkconfig --list

如果3,4,5都是开的就说明是自启设置成功。没有的话,就执行

chkconfig --level 345 mysql on

这里mysql的安装就这样完成了,其他n个mysql的安装,按照以上步骤即可。

  1. 安装过程中遇到的问题
    Starting MySQL. ERROR! The server quit without updating PID file (/data/soft/mysql/data/localhost.localdomain.pid).
    报这个错,可能有2个原因:一是/data/soft/mysql/data,用户对这个目录操作权限不足,可以"chown -R mysql:mysql /data/soft/mysql",然后"chmod -R 755 /data/soft/mysql"。
    二是 /data/soft/mysql/support-files/mysql.server,这个脚本相关参数没有配置对,就要重新认真检查这个文件是否配置正确。
2011-10-12 20:38:07 tangpengtao 阅读数 9398

mysql创建多个实例,其实就是把DATA文件,SOCK,PORT指向不同的文件和端口

mysql安装过程看 http://blog.csdn.net/tangpengtao/article/details/6650424

先创建3307的DATA目录

[root@localhost mysql-5.5.15]# mkdir -p  /usr/local/mysql3307
[root@localhost mysql-5.5.15]#
[root@localhost mysql-5.5.15]#
[root@localhost mysql-5.5.15]# chmod +w /usr/local/mysql3307
[root@localhost mysql-5.5.15]# chown -R mysql:mysql /usr/local/mysql3307
[root@localhost mysql-5.5.15]#
[root@localhost mysql-5.5.15]# mkdir -p /var/mysql3307/
mkdir -p /var/mysql3307/data/
mkdir -p /var/mysql3307/log/
chown -R mysql:mysql /var/mysql3307/
[root@localhost mysql-5.5.15]# mkdir -p /var/mysql3307/data/
[root@localhost mysql-5.5.15]# mkdir -p /var/mysql3307/log/
[root@localhost mysql-5.5.15]# chown -R mysql:mysql /var/mysql3307/

mkdir -p  /usr/local/mysql3307

chmod +w /usr/local/mysql3307
chown -R mysql:mysql /usr/local/mysql3307
mkdir -p /var/mysql3307/

mkdir -p /var/mysql3307/data/

mkdir -p /var/mysql3307/log/

chown -R mysql:mysql /var/mysql3307/


[root@localhost mysql-5.5.15]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql3307 \
> -DMYSQL_UNIX_ADDR=/tmp/mysql3307.sock \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \
> -DWITH_MYISAM_STORAGE_ENGINE=1 \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_READLINE=1 \
> -DENABLED_LOCAL_INFILE=1 \
> -DMYSQL_DATADIR=/var/mysql3307/data \
> ;
-- MySQL 5.5.15
-- Configuring done
-- Generating done
-- Build files have been written to: /home/raycloud/software/mysql-5.5.15
[root@localhost mysql-5.5.15]# 

[root@localhost mysql-5.5.15]# make
-- MySQL 5.5.15
-- Configuring done
-- Generating done
-- Build files have been written to: /home/raycloud/software/mysql-5.5.15
[  0%] Built target INFO_BIN


[root@localhost mysql-5.5.15]# make install

mysql 初始化安装

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


进入到my.cnf然后vi my.cnf

[mysqld3]
port            = 3307 
socket          = /tmp/mysql3307.sock
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
#wait_timeout=100
#interactive_timeout=100
max_connections=1400
user=root
datadir=/var/mysql3307/data

启动mysql

[root@localhost etc]# mysqld_safe --user=root --port=3307 --socket=/tmp/mysql3307.sock --datadir=/var/mysql3307/data &
[2] 7459
[root@localhost etc]# Starting mysqld daemon with databases from /var/mysql3307/data

查看mysql服务是否启动

[root@localhost etc]# ps -ef |grep 3307
root      7459  1624  0 20:18 pts/1    00:00:00 /bin/sh /usr/bin/mysqld_safe --user=root --port=3307 --socket=/tmp/mysql3307.sock --datadir=/var/mysql3307/data
root      7488  7459  0 20:18 pts/1    00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/mysql3307/data --user=root --pid-file=/var/mysql3307/data/localhost.localdomain.pid --skip-external-locking --port=3307 --socket=/tmp/mysql3307.sock
root      7502  1624  0 20:19 pts/1    00:00:00 grep 3307
[root@localhost etc]#

进入mysqlclient 修改密码

[root@localhost etc]# mysql -uroot  --socket=/tmp/mysql3307.sock  --port=3307 -p
Enter password: 

mysql> use mysql;
Database changed
mysql> update user set password=password('yourpassword') where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)


mysql> set character_set_results=utf8
    ->
    ->
    -> ;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like '%char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

mysql>

停止mysql 3307

[root@localhost etc]# mysqladmin -uroot --socket=/tmp/mysql3307.sock --port=3307 -p shutdown
Enter password:
[root@localhost etc]# 

启动3307数据库
[root@localhost etc]# /usr/local/mysql/bin/mysqld_multi  --defaults-file=/etc/my.cnf start  3






2012-10-31 22:19:14 iteye_2369 阅读数 29

 

目标:在服务器安装两个mysql5.5端口分别为3316和3326

 

// 添加mysq用户、l用户组

[root@test02 software]# groupadd mysql

[root@test02 software]# useradd -r -g mysql mysql

 

// 解压

[root@test02 software]# tar zxf mysql-5.5.22-linux2.6-i686.tar.gz

 

// 重命名

[root@test02 software]# mv mysql-5.5.22-linux2.6-i686 mysql-3316

 

// 进入到mysql 安装目录

[root@test02 software]# cd mysql-3316

 

 

// 改变权限

[root@test02 mysql-3316]# chown -R mysql:mysql .

 

// 初始化系统数据库

[root@test02 mysql-3316]# scripts/mysql_install_db --user=mysql

 

//修改配置文件中的端口号和socket文件位置,mysql中提供了多个配置文件模板,这里只修改support-files中的my-samll.cnf

// 将其中的3306改为3316,socket 改为 /tmp/mysql3316.sock

[root@test02 mysql-3316]# vim support-files/my-small.cnf

 

//运行mysql

[root@test02 mysql-3316]# ./bin/mysqld_safe --defaults-file=support-files/my-small.cnf --user=mysql &

[1] 3724
[root@test02 mysql-3316]# 121031 14:12:40 mysqld_safe Logging to '/opt/software/mysql-3316/data/test02.err'.
121031 14:12:40 mysqld_safe Starting mysqld daemon with databases from /opt/software/mysql-3316/data

 

// 修改root密码,这里需要显示指定端口号和socket文件路径
[root@test02 mysql-3316]# ./bin/mysqladmin -u root -P 3316 -S /tmp/mysql3316.sock password '123456'

 

// 连接到数据库,这里需要显示指定端口号和socket文件路径

[root@test02 mysql-3316]# ./bin/mysql -u root -p  -P 3316 -S /tmp/mysql3316.sock
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.5.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

 

这样就安装完了,另一个端口为3326的数据库也按上面这样安装

 

 

[root@test02 mysql-3326]# ps aux|grep mysql
root      3335  0.0  0.1  18592  2028 pts/0    S+   13:56   0:00 ./bin/mysql -uroot -p -P5188 -S/tmp/mysql3316.sock
root      3724  0.0  0.1  63828  1352 pts/1    S    14:12   0:00 /bin/sh ./bin/mysqld_safe --defaults-file=support-files/my-small.cnf --user=mysql
mysql     3939  0.0  3.0 321268 31472 pts/1    Sl   14:12   0:00 /opt/software/mysql-3316/bin/mysqld --defaults-file=support-files/my-small.cnf --basedir=/opt/software/mysql-3316 --datadir=/opt/software/mysql-3316/data --plugin-dir=/opt/software/mysql-3316/lib/plugin --user=mysql --log-error=/opt/software/mysql-3316/data/test02.err --pid-file=/opt/software/mysql-3316/data/test02.pid --socket=/tmp/mysql3316.sock --port=3316
root      4021  0.0  0.1  63828  1352 pts/1    S    14:18   0:00 /bin/sh ./bin/mysqld_safe --defaults-file=support-files/my-small.cnf --user=mysql
mysql     4236  0.1  3.0 321400 31708 pts/1    Sl   14:18   0:00 /opt/software/mysql-3326/bin/mysqld --defaults-file=support-files/my-small.cnf --basedir=/opt/software/mysql-3326 --datadir=/opt/software/mysql-3326/data --plugin-dir=/opt/software/mysql-3326/lib/plugin --user=mysql --log-error=/opt/software/mysql-3326/data/test02.err --pid-file=/opt/software/mysql-3326/data/test02.pid --socket=/tmp/mysql3326.sock --port=3326
root      4267  0.0  0.0  61188   768 pts/1    R+   14:19   0:00 grep mysql
[root@test02 mysql-3326]#

 

 

 

 

 

 

 

 

 

 

 

 

 

linux安装多个mysql

阅读数 394

没有更多推荐了,返回首页