Ubuntu安装多个MySQL

1. 下载安装包

MySQL下载地址:http://dev.mysql.com/downloads/mysql/

选择 Linux - Generic,下载mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz

2. 创建mysql用户组

sudo groupadd mysql;
sudo useradd -r -g mysql -s /bin/false mysql;

3. 创建安装目录以及数据存储目录

# 安装目录
sudo mkdir /mysql;
# 数据存储目录
sudo mkdir -p /mysqldata/mysql3307;
sudo mkdir -p /mysqldata/mysql3308;

4. 解压安装包

cd /mysql;
sudo tar -zxvf /home/unispace/Downloads/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz;
sudo mv mysql-5.7.31-linux-glibc2.12-x86_64 mysql3307;

5. 修改MySQL目录权限

cd mysql3307;
sudo chown -R mysql:mysql .;

6. 创建配置文件

在mysql3307目录中创建my.cnf,配置文件内容如下:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
#
[client]
port = 3307
socket = /mysql/mysql3307/mysqld.sock

[mysqld_safe]
socket = /mysql/mysql3307/mysqld.sock
pid-file = /mysql/mysql3307/mysqld.pid

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
basedir = /mysql/mysql3307
datadir = /mysqldata/mysql3307
port = 3307
server_id = 11
socket = /mysql/mysql3307/mysqld.sock

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

7. 初始化数据库

sudo bin/mysqld --defaults-file=/mysql/mysql3307/my.cnf --initialize --user=mysql;

结果如下:

2016-07-29T15:38:48.896585Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-07-29T15:38:48.896672Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2016-07-29T15:38:48.896682Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2016-07-29T15:38:50.498675Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-07-29T15:38:50.890849Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-07-29T15:38:51.062752Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 8c708a13-55a2-11e6-835e-a0481ced538c.
2016-07-29T15:38:51.088854Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-07-29T15:38:51.090179Z 1 [Note] A temporary password is generated for root@localhost: pJLwjf%q;1t)

其中 pJLwjf%q;1t 为初始密码

8. 加密连接

sudo bin/mysql_ssl_rsa_setup --defaults-file=/mysql/mysql3307/my.cnf;

结果如下:

Generating a 2048 bit RSA private key
.........+++
.......................+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
..........+++
..............................................................+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
................................................+++
........................................+++
writing new private key to 'client-key.pem'
-----

9. 启动MySQL

sudo bin/mysqld_safe --user=mysql &;

10. 登录MySQL

bin/mysql -uroot -p -S /mysql/mysql3307/mysqld.sock

11. 修改密码以及创建远程登录账号

# 修改密码
mysql> SET PASSWORD = PASSWORD('iunispace');
mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
mysql> flush privileges;
# 创建账号
mysql> grant all privileges on *.* to 'root'@'%' identified by 'iunispace' with grant option;

重复上面的步骤,可以安装多个mysql

12. 停止MySQL

bin/mysqladmin -uroot -piunispace -S /var/lib/1_mysql/mysqld.sock shutdown
mysql官网上下载mysql-server_5.7.21-1ubuntu14.04_amd64.deb-bundle.tar,然后进行离线安装,解压该安装包,会出现11个依赖包,按照顺序依次使用sudo dpkg -i 进行安装,中间会报错,显示缺少相应的依赖,具体如下: *******@ubuntu:/opt/mysql$ sudo dpkg -i mysql-community-client_5.7.21-1ubuntu14.04_amd64.deb Selecting previously unselected package mysql-community-client. (Reading database ... 208518 files and directories currently installed.) Preparing to unpack mysql-community-client_5.7.21-1ubuntu14.04_amd64.deb ... Unpacking mysql-community-client (5.7.21-1ubuntu14.04) ... dpkg: dependency problems prevent configuration of mysql-community-client: mysql-community-client depends on libaio1 (>= 0.3.93); however: Package libaio1 is not installed. dpkg: error processing package mysql-community-client (--install): dependency problems - leaving unconfigured Processing triggers for man-db (2.6.7.1-1ubuntu1) ... Errors were encountered while processing: mysql-community-client 和 ********@ubuntu:/opt/mysql$ sudo dpkg -i mysql-community-server_5.7.21-1ubuntu14.04_amd64.deb Selecting previously unselected package mysql-community-server. (Reading database ... 208598 files and directories currently installed.) Preparing to unpack mysql-community-server_5.7.21-1ubuntu14.04_amd64.deb ... Unpacking mysql-community-server (5.7.21-1ubuntu14.04) ... dpkg: dependency problems prevent configuration of mysql-community-server: mysql-community-server depends on libmecab2 (>= 0.996-1.1); however: Package libmecab2 is not installed. dpkg: error processing package mysql-community-server (--install): dependency problems - leaving unconfigured Processing triggers for man-db (2.6.7.1-1ubuntu1) ... Processing triggers for ureadahead (0.100.0-16) ... ureadahead will be reprofiled on next reboot Errors were encountered while processing: mysql-community-server 附上依赖包安装顺序: 1.mysql-common_5.7.21-1ubuntu14.04_amd64.deb 2.libmysqlclient20_5.7.21-1ubuntu14.04_amd64.deb 3.libmysqlclient-dev_5.7.21-1ubuntu14.04_amd64.deb 4.libmysqld-dev_5.7.21-1ubuntu14.04_amd64.deb
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值