开发者社区> club111> 正文

单台[dell R720]服务器部署多个mysql实例

简介: 一、安装mysql准备 1.1 下载mysql软件包 mkdir -p /home/xuekun/mysql cd /home/xuekun/tools/mysql wget http://dev.
+关注继续查看

一、安装mysql准备

1.1 下载mysql软件包

mkdir -p /home/xuekun/mysql

cd /home/xuekun/tools/mysql

wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.10.tar.gz

1.2安装mysql软件

yum -y install make gcc-c++ cmake bison bison-devel  ncurses-devel

tar xvf mysql-5.6.16.tar.gz

cd mysql-5.6.16

cmake \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_DATADIR=/data \

-DSYSCONFDIR=/etc \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \

-DMYSQL_TCP_PORT=3306 \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DEXTRA_CHARSETS=all \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci

 

make && make install

 

1.3创建mysql用户

groupadd mysql

useradd -g mysql -M -s /sbin/nologin mysql

1.4创建mysql数据文件目录

mkdir -p /data/3306/data

mkdir -p /data/3307/data

tree /data/

/data/

|-- 3306

| `-- data

`-- 3307

`-- data

4 directories, 0 files

1.5 授权mysql用户及组访问数据文件目录

chown -R mysql:mysql /data/3306

chown -R mysql:mysql /data/3307

1.6 建立3306,3307 my.cnf配置文件

vim  /data/3306/my.cnf

vim  /data/3307/my.cnf

需要添加的my.cnf内容见附录B:或本文档目录下的my.cnf文件

#授权mysql用户及组访问my.cnf

chown -R mysql:mysql /data/3306/my.cnf

chown -R mysql:mysql /data/3307/my.cnf

1.7 建立mysql启动脚本

vim  /data/3306/mysql

vim  /data/3307/mysql

 

需要添加的mysql 内容见附录C:或本文档目录下的mysql文件

chmod 700 /data/3306/mysql

chmod 700 /data/3307/mysql

1.8 初始化数据库

vim /etc/profile

PATH=/usr/local/mysql/bin:$PATH

export PATH

#关闭文件,运行下面的命令,让配置立即生效

source /etc/profile

cd /usr/local/mysql

scripts/mysql_install_db --datadir=/data/3306/data

Installing MySQL system tables...

OK

Filling help tables...

OK

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

/usr/local/mysql/bin/mysqladmin -u root password 'new-password'

/usr/local/mysql/bin/mysqladmin -u root -h A password 'new-password'

Alternatively you can run:

/usr/local/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test

databases and anonymous user created by default. This is

strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/local/mysql/bin/mysqlbug script!

 

scripts/mysql_install_db --datadir=/data/3307/data

Installing MySQL system tables...

OK

Filling help tables...

OK

同上面3306的内容,因此,此处省略。

 

chown -R mysql:mysql /data

1.9 启动数据库

启动mysql实例的命令为

/data/3306/mysql start

Starting MySQL...

/data/3307/mysql start

Starting MySQL...

检查启动情况:

netstat -lnt|grep 330[6-7]

tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN

tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN

并加入/etc/rc.local,设置为开机自启动

echo "/data/3306/mysql start" >>/etc/rc.local

echo "/data/3307/mysql start" >>/etc/rc.local

cat /etc/rc.local

#!/bin/sh

#

# This script will be executed *after* all the other init scripts.

# You can put your own initialization stuff in here if you don't

# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

/data/3306/mysql start

/data/3307/mysql start

提示:如果此步中的数据库启动不了,请稍微等待下,如果还不行请查看错误日志,路径在my.cnf的最下面。

二、配置mysql数据库

2.1 访问测试登陆情况

mysql -uroot -p -S /data/3306/mysql.sock

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.1.51-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select version();

+------------+

| version() |

+------------+

| 5.1.51-log |

+------------+

1 row in set (0.02 sec)

mysql> system mysql -uroot -p -S /data/3307/mysql.sock #-->system的用法

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.1.51-log Source distribution

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

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license

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

mysql> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| test |

+--------------------+

3 rows in set (0.01 sec)

mysql> quit

Bye

提示:安装完mysql初始登陆管理员root用户无密码。

更改root密码

mysqladmin -u root password 'bdkyr14511' -S /data/3306/mysql.sock

mysqladmin -u root password 'bdkyr14511' -S /data/3307/mysql.sock

#测试改密码后的登陆情况

mysql -uroot -p'bdkyr14511' -S /data/3306/mysql.sock

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.1.51-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> system mysql -uroot -p'bdkyr14511' -S /data/3307/mysql.sock

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

mysql> system mysql -uroot -p'hyran0926' -S /data/3307/mysql.sock

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.1.51-log Source distribution

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

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license

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

提示:一般产品环境,禁止将密码写在命令行中,非常危险。

2.2清理系统默认的多余mysql用户

mysql -uroot -p'bdkyr14511' -S /data/3306/mysql.sock

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.1.51-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select user,host from mysql.user;

+------+-----------+

| user | host |

+------+-----------+

| root | 127.0.0.1 |

| | A |

| root | A |

| | localhost |

| root | localhost |

+------+-----------+

5 rows in set (0.00 sec)

mysql> drop user ''@'localhost';

Query OK, 0 rows affected (0.04 sec)

mysql> drop user ''@'A';

Query OK, 0 rows affected (0.01 sec)

mysql> drop user 'root'@'A';

Query OK, 0 rows affected (0.00 sec)

mysql> select user,host from mysql.user;

+------+-----------+

| user | host |

+------+-----------+

| root | 127.0.0.1 |

| root | localhost |

+------+-----------+

2 rows in set (0.00 sec)

用同样的方法处理3307的用户。

处理后结果:

mysql> select user,host from mysql.user;

+------+-----------+

| user | host |

+------+-----------+

| root | 127.0.0.1 |

| root | localhost |

+------+-----------+

2 rows in set (0.00 sec)

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
MySQL实例启动过程(上):server层
前言MySQL是一个庞大的数据库系统,对于数据库内核研发人员来说,非常有必要了解MySQL实例的启动过程。对于数据库使用人员来说,也需要对MySQL实例的启动过程有一个基本的了解。​本文旨在对MySQL Server层的启动过程做一个整体的介绍,让读者对Server层启动整体流程有一个基本的认识。可将本文看作一个手册,用于查询server相关启动过程,需要深入理解时再对启动源码进行分析。下面以My
12 0
阿里云数据库RDS MySQL倚天ARM实例降价25-40%
阿里云数据库RDS MySQL倚天ARM实例降价25-40%,阿里云产品大规模调价,核心云产品价格全线下调,技术红利释放核心产品最高降幅50%,以下产品的价格调整将于2023年5月7日生效,最终以产品详情页实际情况为准,阿里云百科分享阿里云官网发布的降价产品及降价幅度说明:
48 0
猿创征文|MySQL基本查询语句的应用(有实例与代码)
猿创征文|MySQL基本查询语句的应用(有实例与代码)
47 0
MySQL复杂查询使用实例
MySQL复杂查询使用实例
23 0
MySQL在Windows平台上的安装及实例多开
MySQL在Windows平台上的安装及实例多开
29 0
位运算的简介与实例(Mysql)
位运算的简介与实例(Mysql)
35 0
访问 MySQL 数据库——创建 MySQL 实例
访问 MySQL 数据库——创建 MySQL 实例自制脑图
18 0
MySQL数据库的数据类型和基于MySQL数据类型的综合实例项目(下)
MySQL数据库的数据类型和基于MySQL数据类型的综合实例项目(下)
50 0
MySQL数据库的数据类型和基于MySQL数据类型的综合实例项目(中)
MySQL数据库的数据类型和基于MySQL数据类型的综合实例项目(中)
48 0
MySQL数据库的数据类型和基于MySQL数据类型的综合实例项目(上)
MySQL数据库的数据类型和基于MySQL数据类型的综合实例项目
39 0
+关注
club111
老薛Linux大讲堂
文章
问答
视频
文章排行榜
最热
最新
相关电子书
更多
高效MySQL的N个习惯
立即下载
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
相关镜像