1.初始化数据库

在$mysql_base目录下,新增加存放data的文件夹,用mysql_install_db命令执行初始化

[root@ora11g scripts]# ./mysql_install_db --help | less
Usage: ./mysql_install_db [OPTIONS]
  --basedir=path       The path to the MySQL installation directory.
  --builddir=path      If using --srcdir with out-of-directory builds, you
                       will need to set this to the location of the build
                       directory where built files reside.
  --cross-bootstrap    For internal use.  Used when building the MySQL system
                       tables on a different host than the target.
  --datadir=path       The path to the MySQL data directory.
  --defaults-extra-file=name
                       Read this file after the global files are read.
  --defaults-file=name Only read default options from the given file name.
  --force              Causes mysql_install_db to run even if DNS does not
                       work.  In that case, grant table entries that normally
                       use hostnames will use IP addresses.
  --help               Display this help and exit.
  --ldata=path         The path to the MySQL data directory. Same as --datadir.
  --no-defaults        Don't read default options from any option file.
  --rpm                For internal use.  This option is used by RPM files
                       during the MySQL installation process.
  --skip-name-resolve  Use IP addresses rather than hostnames when creating
                       grant table entries.  This option can be useful if
                       your DNS does not work.
  --srcdir=path        The path to the MySQL source directory.  This option
                       uses the compiled binaries and support files within the
                       source tree, useful for if you don't want to install
                       MySQL yet and just want to create the system tables.
  --user=user_name     The login username to use for running mysqld.  Files
                       and directories created by mysqld will be owned by this
                       user.  You must be root to use this option.  By default
                       mysqld runs using your current login name and files and
                       directories that it creates will be owned by you.

All other options are passed to the mysqld program
[root@ora11g scripts]# ./mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data2 --user=mysql
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 ora11g 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 at http://bugs.mysql.com/

[root@ora11g scripts]# 

同样,再初始化一个data3

修改my.cnf的配置,添加上multi的相关属性,如果不是很清楚需要添加什么的话,可以参考mult给的例子

[root@ora11g ~]# mysqld_multi --example

[mysqld_multi]
mysqld     = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user       = multi_admin
password   = my_password

[mysqld2]
socket     = /tmp/mysql.sock2
port       =
pid-file   = /usr/local/mysql/mysqldata2/hostname.pid2
datadir    = /usr/local/mysql/mysqldata2
language   = /usr/local/mysql/share/mysql/english
user       = unix_user1

[mysqld3]
mysqld     = /path/to/mysqld_safe
ledir      = /path/to/mysqld-binary/
mysqladmin = /path/to/mysqladmin
socket     = /tmp/mysql.sock3
port       =
pid-file   = /usr/local/mysql/mysqldata3/hostname.pid3
datadir    = /usr/local/mysql/mysqldata3
language   = /usr/local/mysql/share/mysql/swedish
user       = unix_user2

[mysqld4]
socket     = /tmp/mysql.sock4
port       =
pid-file   = /usr/local/mysql/mysqldata4/hostname.pid4
datadir    = /usr/local/mysql/mysqldata4
language   = /usr/local/mysql/share/mysql/estonia
user       = unix_user3

[mysqld6]
socket     = /tmp/mysql.sock6
port       =
pid-file   = /usr/local/mysql/mysqldata6/hostname.pid6
datadir    = /usr/local/mysql/mysqldata6
language   = /usr/local/mysql/share/mysql/japanese
user       = unix_user4
[root@ora11g ~]# 

我的相关配置如下:

[mysqld_multi]
mysqld     = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user       = test
password   = test

# The MySQL server
[mysqld3306]
port            =
socket          = /tmp/mysql3306.sock
pid-file        = /tmp/mysql3306.pid
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache =
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
server-

[mysqld3307]
port            =
socket          = /tmp/mysql3307.sock
pid-file        = /tmp/mysql3307.pid
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache =
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data2
server-

[mysqld3308]
port            =
socket          = /tmp/mysql3308.sock
pid-file        = /tmp/mysql3308.pid
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache =
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data3
server-

主要需要注意的几个参数是:[mysqld_multi],port,socket,pid-file和datadir。

配置好之后,就可以启动了。

[root@ora11g bin]# ./mysqld_multi --defaults-
[root@ora11g bin]# ps -ef | grep mysq;
root             : pts/    :: /bin/ --socket=/tmp/mysql3306.sock --pid- --sort_buffer_size=64K --read_buffer_size=256K --read_rnd_buffer_size=256K --net_buffer_length=2K --thread_stack=128K --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --server-
mysql        : pts/    :: /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin- -- --log-error=/usr/local/mysql/data/ora11g.err --pid-
root          : pts/    :: grep mysq
[root@ora11g bin]# ps -ef | grep mysql
root             : pts/    :: /bin/ --socket=/tmp/mysql3306.sock --pid- --sort_buffer_size=64K --read_buffer_size=256K --read_rnd_buffer_size=256K --net_buffer_length=2K --thread_stack=128K --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --server-
mysql        : pts/    :: /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin- -- --log-error=/usr/local/mysql/data/ora11g.err --pid-
root          : pts/    :: grep mysql
[root@ora11g bin]# ./mysqld_multi --defaults-
[root@ora11g bin]# ./mysqld_multi --defaults-
[root@ora11g bin]# ps -ef | grep mysql
root             : pts/    :: /bin/ --socket=/tmp/mysql3306.sock --pid- --sort_buffer_size=64K --read_buffer_size=256K --read_rnd_buffer_size=256K --net_buffer_length=2K --thread_stack=128K --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --server-
mysql        : pts/    :: /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin- -- --log-error=/usr/local/mysql/data/ora11g.err --pid-
root             : pts/    :: /bin/ --socket=/tmp/mysql3307.sock --pid- --sort_buffer_size=64K --read_buffer_size=256K --read_rnd_buffer_size=256K --net_buffer_length=2K --thread_stack=128K --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data2 --server-
mysql        : pts/    :: /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data2 --plugin- -- --log-error=/usr/local/mysql/data2/ora11g.err --pid-
root             : pts/    :: /bin/ --socket=/tmp/mysql3308.sock --pid- --sort_buffer_size=64K --read_buffer_size=256K --read_rnd_buffer_size=256K --net_buffer_length=2K --thread_stack=128K --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data3 --server-
mysql       : pts/    :: /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data3 --plugin- -- --log-error=/usr/local/mysql/data3/ora11g.err --pid-
root          : pts/    :: grep mysql
[root@ora11g bin]# 

中间有一个小插曲,因为我在安装mysql的时候,cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc\ ,当时制定的DMYSQL_DATADIR为mysqldata,所以在启动的时候,会报错:

[root@ora11g share]# more mysqld_multi.log
mysqld_multi log  :: 

Starting MySQL servers

 :: [Warning] Can't create test file /usr/local/mysql/mysqldata/ora11g.lower-test
 :: [Warning] Can't create test file /usr/local/mysql/mysqldata/ora11g.lower-test
/usr/local/mysql/bin/mysqld: Can't change dir to '/usr/local/mysql/mysqldata/' (Errcode: 2)
 :: [ERROR] Aborting

 :: [Note] /usr/local/mysql/bin/mysqld: Shutdown complete

mysqld_multi log  :: 

Starting MySQL servers

 :: [Warning] Can't create test file /usr/local/mysql/mysqldata/ora11g.lower-test
 :: [Warning] Can't create test file /usr/local/mysql/mysqldata/ora11g.lower-test
/usr/local/mysql/bin/mysqld: Can't change dir to '/usr/local/mysql/mysqldata/' (Errcode: 2)
 :: [ERROR] Aborting

只需要把mysql_safe里面相应的data的目录从mysqldata改为data就可以正常启动了。

# Next try where the source installs put it
elif test -d $MY_BASEDIR_VERSION/var/mysql
then
  DATADIR=$MY_BASEDIR_VERSION/var
# Or just give up and use our compiled-in default
else
  DATADIR=/usr/local/mysql/data
fi

再进数据库查看:

[root@ora11g bin]# cd /tmp
[root@ora11g tmp]# ls
keyring-HcV70B  mysql3306.pid   mysql3307.pid   mysql3308.pid   scim-panel-socket:-root  vmware-root
mapping-root    mysql3306.sock  mysql3307.sock  mysql3308.sock  ssh-WENobU7545
[root@ora11g tmp]# ll
total
drwx------  root  root   Sep    keyring-HcV70B
srwxr-xr-x  root  root      Sep    mapping-root
-rw-rw----  mysql mysql     Mar  : mysql3306.pid
srwxrwxrwx  mysql mysql     Mar  : mysql3306.sock
-rw-rw----  mysql mysql     Mar  : mysql3307.pid
srwxrwxrwx  mysql mysql     Mar  : mysql3307.sock
-rw-rw----  mysql mysql     Mar  : mysql3308.pid
srwxrwxrwx  mysql mysql     Mar  : mysql3308.sock
srw-------  root  root      Nov    scim-panel-socket:-root
drwx------  root  root   Mar  : ssh-WENobU7545
drwx------  root  root   Mar  : vmware-root
[root@ora11g tmp]# mysql -S mysql3306.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection
Server version:  Source distribution

Copyright (c) , , 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
 rows in set (0.00 sec)

mysql> exit
Bye
[root@ora11g tmp]# mysql -S mysql3308.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection
Server version:  Source distribution

Copyright (c) , , 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
 rows in set (0.00 sec)

mysql> exit
Bye
[root@ora11g tmp]# 

当想使用stop来关闭的时候:

[root@ora11g mysql]# mysqld_multi --defaults-file=my.cnf stop 3306

发现log里面报错:

mysqld_multi log file version 2.16; run: Fri Mar 28 13:42:17 2014

Stopping MySQL servers

/usr/local/mysql/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'test'@'localhost' (using password: YES)'

原来是相应的数据库里面还没有这个用户以及相应的权限。

去数据库中创建用户并授权:

[root@ora11g tmp]# ls -lrt
total
srw-------  root  root      Nov    scim-panel-socket:-root
drwx------  root  root   Sep    keyring-HcV70B
srwxr-xr-x  root  root      Sep    mapping-root
drwx------  root  root   Mar  : vmware-root
drwx------  root  root   Mar  : ssh-WENobU7545
srwxrwxrwx  mysql mysql     Mar  : mysql3306.sock
-rw-rw----  mysql mysql     Mar  : mysql3306.pid
srwxrwxrwx  mysql mysql     Mar  : mysql3307.sock
-rw-rw----  mysql mysql     Mar  : mysql3307.pid
srwxrwxrwx  mysql mysql     Mar  : mysql3308.sock
-rw-rw----  mysql mysql     Mar  : mysql3308.pid
[root@ora11g tmp]# mysql -S mysql3306.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection
Server version:  Source distribution

Copyright (c) , , 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> grant shutdown on *.* to test@localhost identified by 'test' with grant option;
Query OK,  rows affected (0.00 sec)

mysql> show grants for test@localhost;
+---------------------------------------------------------------+
| Grants for test@localhost                                     |
+---------------------------------------------------------------+
| GRANT SHUTDOWN ON *.* TO 'test'@'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------+
 row in set (0.01 sec)

mysql> 

创建完毕后,再去停数据库:

[root@ora11g mysql]# mysqld_multi --defaults-file=my.cnf stop 3306-3308
[root@ora11g mysql]# ps -ef | grep 3306
root 11551 7661 0 13:49 pts/2 00:00:00 mysql -S mysql3306.sock
root 11583 7547 0 13:51 pts/1 00:00:00 grep 3306

可以在日志中发现已经能正常的进行关闭了。
Stopping MySQL servers

140328 13:50:53 mysqld_safe mysqld from pid file /tmp/mysql3306.pid ended

相应的,在tmp目录下面的socket文件也会相应的删除了。

140328 13:50:55 mysqld_safe mysqld from pid file /tmp/mysql3307.pid ended
mysqld_multi log file version 2.16; run: Fri Mar 28 13:50:56 2014

Stopping MySQL servers

140328 13:50:57 mysqld_safe mysqld from pid file /tmp/mysql3308.pid ended

mysql_multi启动数据库的更多相关文章

  1. oracle在cmd中启动数据库实例

    在cmd中启动数据库实例: sqlplus /nolog 回车, conn as sysdba;回车,startup;然后回车

  2. sqlserver如何启动数据库邮件

    可以在 msdb 数据库中停止数据库邮件.若要检查数据库邮件的状态,请执行下面的语句: 复制 EXECUTE dbo.sysmail_help_status_sp; 若要在邮件主机数据库中启动数据库邮 ...

  3. hsql使用架构包启动数据库

    一.通常我们平时启动就是直接通过hsql.jar来进行启动 java -cp hsqldb.jar org.hsqldb.util.DatabaseManagerSwing java -cp hsql ...

  4. Oracle11g 启动数据库实例、关闭数据库实例

    Oracle11g 启动数据库实例        startup 1: nomount 模式:      描述:             该模式只会创建实例(即:创建oracle 实例的各种内存结构和 ...

  5. linux环境:创建数据库用户,表空间,启动数据库

    1.启动数据库 首先使用oracle用户登录Linux,然后在shell命令行中执行下面的命令:第一步:打开Oracle监听(先查看状态:oracle监听是否启动:lsnrctl status)$ l ...

  6. linux环境启动数据库

    1.查看数据库监听的状态: 监听状态:lsnrctl status  出现如下列截图所示数据,说明切切换账户有问题:切换账户时要家:-:  如 su - oracle 第一步:打开Oracle监听$ ...

  7. 第15课-数据库开发及ado.net-数据库介绍,主键,外键,启动数据库,数据库身份验证方式,建表,分离数据库

    第15课-数据库开发及ado.net 数据库介绍,主键,外键,启动数据库,数据库身份验证方式,建表,分离数据库 1.  学习方法 2.  多涨见识 3.  比自己强的人一起,学习更强:比自己更聪明的人 ...

  8. oracle 启动数据库与监听器

    1.oracle 启动数据库与监听器 1)启动数据库 oracle用户进去 oracle/oracle sqlplus / as sysdba 然后startup 退出,然后启动监听进程 2)启动监听 ...

  9. Linux 启动数据库报错:could not open parameter file init**.ora

    sqlplus /nolog.conn /as sysdba.startup命令后显示 SQL> startupORA-01078: failure in processing system p ...

随机推荐

  1. 《oracle每天一练》Oracle之物化视图

    相关帖子思考和跟踪 本文转自Ronger 物化视图是一种特殊的物理表,“物化”(Materialized)视图是相对普通视图而言的.普通视图是虚拟表,应用的局限性大,任何对视图的查询,Oracle都实 ...

  2. 怎样将myeclipse里默认编码设置成utf-8

    需要设置三个位置: [1]需要在  Preferences->general->content types->下角是文件编码,可以自己定义 [2]windows->Prefer ...

  3. 提高AdoQuery的速度

    用TDataSet及其派生类如TAdoQuery对数据库进行查找时, 如果TDataSet类 没有与数据感知控件相连,通过调用DisableControls可以极大地提高查询速度 特别是在数据比较多的 ...

  4. 3.js模式-策略模式

    1. 策略模式 策略模式定义一系列的算法,把它们封装起来,并且可以互相替换. var strategies = { isNonEmpty: function(value,errMsg){ if(val ...

  5. MySQL 通过idb文件恢复Innodb 数据【转】

    昨晚收到一则求助,一个用户的本地数据库的重要数据由于误操作被删除,需要进行紧急恢复,用户的数据库日常并没有进行过任何备份,binlog也没有开启,所以从备份和binlog入手已经成为不可能,咨询了丁奇 ...

  6. ffmpeg-20160617-git-bin.7z ffmpeg-20160626-git-bin.7z

    ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 S 下一帧 [ -2秒 ] +2秒 ; -1秒 ' +1秒 下一个帧 -> -5秒 f ...

  7. Python缩小图像

    LyncLynn用途: 缩小图像 # -*- coding: UTF-8 -*- #Version: V1.0 #Author:lynclynn #CreateDate:20151201 #Updat ...

  8. 在Linux下记录所有用户的登录和操作日志

    一般我们可以用history命令来查看用户的操作记录,但是这个命令不能记录是哪个用户登录操作的,也不能记录详细的操作时间,且不完整:所以误操作而造成重要的数据丢失,就很难查到是谁操作的. 在这里我们通 ...

  9. suse linux 10 下配置vpn服务器(pptp)

     一.安装所需的软件包:      pptpd-*.rpm      ppp-*.rpm      pptp-*.rpm     一般情况下系统已经将pptp和ppp包安装好了,所以只需安装pptpd ...

  10. java基础学习05(面向对象基础02)

    面向对象基础02 实现的目标 1.String类的使用2.掌握this关键字的使用3.掌握static关键字的使用4.了解内部类 String类 实例化String对象一个字符串就是一个String类 ...