Maison > Article > base de données > Mysql 5.5多实例部署步骤_MySQL
由于临时的需求,需要在一台主机上启动多个mysql的实例,对应不同的端口。
步骤如下:
1,安装mysql。
2,分别设置不同实例的配置文件。
3,创建不同实例的datadir,并执行数据库初始化。
4,启动不同的mysql实例。
以下是详细的安装方法:
1,安装mysql
使用源码安装.
<code class="hljs lasso">tar -zxvf mysql-5.5.49.tar.gz cd mysql-5.5.49 mkdir /usr/local/mysql cmake - -DCMAKE_INSTALL_PREFIX=/usr/local/mysql make make install </code>
2,先设置下my.cnf
<code class="hljs lasso"><code class="hljs lasso"> cp support-files/my-medium.cnf /etc/my.cnf chown mysql:mysql -R /usr/local/mysql/ ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/dbdata/mysql/data 初始化数据库 </code></code>
<code class="hljs lasso">3,设置不同的目录文件
<code class="hljs lasso"><code class="hljs lasso"><code class="hljs makefile">mkdir -p /dbdata/{3307,3308,3309}/data cp /etc/my.cnf /dbdata/3307/ cp /etc/my.cnf /dbdata/3308/ cp /etc/my.cnf /dbdata/3309/ vim /dbdata/3307/my.cnf ++++++++++++++++++ [client] port = 3307 socket = /dbdata/3307/mysql.sock [mysqld] port = 3307 socket = /dbdata/3307/mysql.sock 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 skip-name-resolve basedir = /usr/local/mysql datadir = /dbdata/3307/data 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 [mysqld_safe] log-error=/dbdata/3307/3307.err pid-file=/dbdata/3307/3307.pid</code></code></code>
<code class="hljs lasso"><code class="hljs makefile">分别更改 3308 3309端口的配置文件<br>
4,初始化启动
<code class="hljs lasso"><code class="hljs lasso"><code class="hljs makefile"><code class="hljs lasso">/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/dbdata/3307/data --user=mysql /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/dbdata/3308/data --user=mysql /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/dbdata/3309/data --user=mysql 启动: /usr/local/mysql/bin/mysqld_safe --defaults-file=/dbdata/3307/my.cnf & /usr/local/mysql/bin/mysqld_safe --defaults-file=/dbdata/3308/my.cnf & /usr/local/mysql/bin/mysqld_safe --defaults-file=/dbdata/3309/my.cnf & 登陆: mysql -uroot -p -S /dbdata/3308/mysql.sock 更改密码 mysqladmin -uroot -p password 123456 -S /dbdata/3307/mysql.sock </code></code></code></code>
<code class="hljs lasso"><code class="hljs makefile"><code class="hljs lasso">完成。