1.初始化数据库

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

  1. [root@ora11g scripts]# ./mysql_install_db --help | less
  2. Usage: ./mysql_install_db [OPTIONS]
  3. --basedir=path The path to the MySQL installation directory.
  4. --builddir=path If using --srcdir with out-of-directory builds, you
  5. will need to set this to the location of the build
  6. directory where built files reside.
  7. --cross-bootstrap For internal use. Used when building the MySQL system
  8. tables on a different host than the target.
  9. --datadir=path The path to the MySQL data directory.
  10. --defaults-extra-file=name
  11. Read this file after the global files are read.
  12. --defaults-file=name Only read default options from the given file name.
  13. --force Causes mysql_install_db to run even if DNS does not
  14. work. In that case, grant table entries that normally
  15. use hostnames will use IP addresses.
  16. --help Display this help and exit.
  17. --ldata=path The path to the MySQL data directory. Same as --datadir.
  18. --no-defaults Don't read default options from any option file.
  19. --rpm For internal use. This option is used by RPM files
  20. during the MySQL installation process.
  21. --skip-name-resolve Use IP addresses rather than hostnames when creating
  22. grant table entries. This option can be useful if
  23. your DNS does not work.
  24. --srcdir=path The path to the MySQL source directory. This option
  25. uses the compiled binaries and support files within the
  26. source tree, useful for if you don't want to install
  27. MySQL yet and just want to create the system tables.
  28. --user=user_name The login username to use for running mysqld. Files
  29. and directories created by mysqld will be owned by this
  30. user. You must be root to use this option. By default
  31. mysqld runs using your current login name and files and
  32. directories that it creates will be owned by you.
  33.  
  34. All other options are passed to the mysqld program
  1. [root@ora11g scripts]# ./mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data2 --user=mysql
  2. Installing MySQL system tables...
  3. OK
  4. Filling help tables...
  5. OK
  6.  
  7. To start mysqld at boot time you have to copy
  8. support-files/mysql.server to the right place for your system
  9.  
  10. PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
  11. To do so, start the server, then issue the following commands:
  12.  
  13. /usr/local/mysql/bin/mysqladmin -u root password 'new-password'
  14. /usr/local/mysql/bin/mysqladmin -u root -h ora11g password 'new-password'
  15.  
  16. Alternatively you can run:
  17. /usr/local/mysql/bin/mysql_secure_installation
  18.  
  19. which will also give you the option of removing the test
  20. databases and anonymous user created by default. This is
  21. strongly recommended for production servers.
  22.  
  23. See the manual for more instructions.
  24.  
  25. You can start the MySQL daemon with:
  26. cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &
  27.  
  28. You can test the MySQL daemon with mysql-test-run.pl
  29. cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl
  30.  
  31. Please report any problems at http://bugs.mysql.com/
  32.  
  33. [root@ora11g scripts]#

同样,再初始化一个data3

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

  1. [root@ora11g ~]# mysqld_multi --example
  2.  
  3. [mysqld_multi]
  4. mysqld = /usr/local/mysql/bin/mysqld_safe
  5. mysqladmin = /usr/local/mysql/bin/mysqladmin
  6. user = multi_admin
  7. password = my_password
  8.  
  9. [mysqld2]
  10. socket = /tmp/mysql.sock2
  11. port =
  12. pid-file = /usr/local/mysql/mysqldata2/hostname.pid2
  13. datadir = /usr/local/mysql/mysqldata2
  14. language = /usr/local/mysql/share/mysql/english
  15. user = unix_user1
  16.  
  17. [mysqld3]
  18. mysqld = /path/to/mysqld_safe
  19. ledir = /path/to/mysqld-binary/
  20. mysqladmin = /path/to/mysqladmin
  21. socket = /tmp/mysql.sock3
  22. port =
  23. pid-file = /usr/local/mysql/mysqldata3/hostname.pid3
  24. datadir = /usr/local/mysql/mysqldata3
  25. language = /usr/local/mysql/share/mysql/swedish
  26. user = unix_user2
  27.  
  28. [mysqld4]
  29. socket = /tmp/mysql.sock4
  30. port =
  31. pid-file = /usr/local/mysql/mysqldata4/hostname.pid4
  32. datadir = /usr/local/mysql/mysqldata4
  33. language = /usr/local/mysql/share/mysql/estonia
  34. user = unix_user3
  35.  
  36. [mysqld6]
  37. socket = /tmp/mysql.sock6
  38. port =
  39. pid-file = /usr/local/mysql/mysqldata6/hostname.pid6
  40. datadir = /usr/local/mysql/mysqldata6
  41. language = /usr/local/mysql/share/mysql/japanese
  42. user = unix_user4
  43. [root@ora11g ~]#

我的相关配置如下:

  1. [mysqld_multi]
  2. mysqld = /usr/local/mysql/bin/mysqld_safe
  3. mysqladmin = /usr/local/mysql/bin/mysqladmin
  4. user = test
  5. password = test
  6.  
  7. # The MySQL server
  8. [mysqld3306]
  9. port =
  10. socket = /tmp/mysql3306.sock
  11. pid-file = /tmp/mysql3306.pid
  12. skip-external-locking
  13. key_buffer_size = 16K
  14. max_allowed_packet = 1M
  15. table_open_cache =
  16. sort_buffer_size = 64K
  17. read_buffer_size = 256K
  18. read_rnd_buffer_size = 256K
  19. net_buffer_length = 2K
  20. thread_stack = 128K
  21. basedir = /usr/local/mysql
  22. datadir = /usr/local/mysql/data
  23. server-
  24.  
  25. [mysqld3307]
  26. port =
  27. socket = /tmp/mysql3307.sock
  28. pid-file = /tmp/mysql3307.pid
  29. skip-external-locking
  30. key_buffer_size = 16K
  31. max_allowed_packet = 1M
  32. table_open_cache =
  33. sort_buffer_size = 64K
  34. read_buffer_size = 256K
  35. read_rnd_buffer_size = 256K
  36. net_buffer_length = 2K
  37. thread_stack = 128K
  38. basedir = /usr/local/mysql
  39. datadir = /usr/local/mysql/data2
  40. server-
  41.  
  42. [mysqld3308]
  43. port =
  44. socket = /tmp/mysql3308.sock
  45. pid-file = /tmp/mysql3308.pid
  46. skip-external-locking
  47. key_buffer_size = 16K
  48. max_allowed_packet = 1M
  49. table_open_cache =
  50. sort_buffer_size = 64K
  51. read_buffer_size = 256K
  52. read_rnd_buffer_size = 256K
  53. net_buffer_length = 2K
  54. thread_stack = 128K
  55. basedir = /usr/local/mysql
  56. datadir = /usr/local/mysql/data3
  57. server-

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

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

  1. [root@ora11g bin]# ./mysqld_multi --defaults-
  2. [root@ora11g bin]# ps -ef | grep mysq;
  3. 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-
  4. 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-
  5. root : pts/ :: grep mysq
  6. [root@ora11g bin]# ps -ef | grep mysql
  7. 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-
  8. 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-
  9. root : pts/ :: grep mysql
  10. [root@ora11g bin]# ./mysqld_multi --defaults-
  11. [root@ora11g bin]# ./mysqld_multi --defaults-
  12. [root@ora11g bin]# ps -ef | grep mysql
  13. 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-
  14. 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-
  15. 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-
  16. 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-
  17. 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-
  18. 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-
  19. root : pts/ :: grep mysql
  20. [root@ora11g bin]#

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

  1. [root@ora11g share]# more mysqld_multi.log
  2. mysqld_multi log ::
  3.  
  4. Starting MySQL servers
  5.  
  6. :: [Warning] Can't create test file /usr/local/mysql/mysqldata/ora11g.lower-test
  7. :: [Warning] Can't create test file /usr/local/mysql/mysqldata/ora11g.lower-test
  8. /usr/local/mysql/bin/mysqld: Can't change dir to '/usr/local/mysql/mysqldata/' (Errcode: 2)
  9. :: [ERROR] Aborting
  10.  
  11. :: [Note] /usr/local/mysql/bin/mysqld: Shutdown complete
  12.  
  13. mysqld_multi log ::
  14.  
  15. Starting MySQL servers
  16.  
  17. :: [Warning] Can't create test file /usr/local/mysql/mysqldata/ora11g.lower-test
  18. :: [Warning] Can't create test file /usr/local/mysql/mysqldata/ora11g.lower-test
  19. /usr/local/mysql/bin/mysqld: Can't change dir to '/usr/local/mysql/mysqldata/' (Errcode: 2)
  20. :: [ERROR] Aborting

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

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

再进数据库查看:

  1. [root@ora11g bin]# cd /tmp
  2. [root@ora11g tmp]# ls
  3. keyring-HcV70B mysql3306.pid mysql3307.pid mysql3308.pid scim-panel-socket:-root vmware-root
  4. mapping-root mysql3306.sock mysql3307.sock mysql3308.sock ssh-WENobU7545
  5. [root@ora11g tmp]# ll
  6. total
  7. drwx------ root root Sep keyring-HcV70B
  8. srwxr-xr-x root root Sep mapping-root
  9. -rw-rw---- mysql mysql Mar : mysql3306.pid
  10. srwxrwxrwx mysql mysql Mar : mysql3306.sock
  11. -rw-rw---- mysql mysql Mar : mysql3307.pid
  12. srwxrwxrwx mysql mysql Mar : mysql3307.sock
  13. -rw-rw---- mysql mysql Mar : mysql3308.pid
  14. srwxrwxrwx mysql mysql Mar : mysql3308.sock
  15. srw------- root root Nov scim-panel-socket:-root
  16. drwx------ root root Mar : ssh-WENobU7545
  17. drwx------ root root Mar : vmware-root
  18. [root@ora11g tmp]# mysql -S mysql3306.sock
  19. Welcome to the MySQL monitor. Commands end with ; or \g.
  20. Your MySQL connection
  21. Server version: Source distribution
  22.  
  23. Copyright (c) , , Oracle and/or its affiliates. All rights reserved.
  24.  
  25. Oracle is a registered trademark of Oracle Corporation and/or its
  26. affiliates. Other names may be trademarks of their respective
  27. owners.
  28.  
  29. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  30.  
  31. mysql> show databases;
  32. +--------------------+
  33. | Database |
  34. +--------------------+
  35. | information_schema |
  36. | mysql |
  37. | performance_schema |
  38. | test |
  39. +--------------------+
  40. rows in set (0.00 sec)
  41.  
  42. mysql> exit
  43. Bye
  44. [root@ora11g tmp]# mysql -S mysql3308.sock
  45. Welcome to the MySQL monitor. Commands end with ; or \g.
  46. Your MySQL connection
  47. Server version: Source distribution
  48.  
  49. Copyright (c) , , Oracle and/or its affiliates. All rights reserved.
  50.  
  51. Oracle is a registered trademark of Oracle Corporation and/or its
  52. affiliates. Other names may be trademarks of their respective
  53. owners.
  54.  
  55. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  56.  
  57. mysql> show databases;
  58. +--------------------+
  59. | Database |
  60. +--------------------+
  61. | information_schema |
  62. | mysql |
  63. | performance_schema |
  64. | test |
  65. +--------------------+
  66. rows in set (0.00 sec)
  67.  
  68. mysql> exit
  69. Bye
  70. [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)'

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

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

  1. [root@ora11g tmp]# ls -lrt
  2. total
  3. srw------- root root Nov scim-panel-socket:-root
  4. drwx------ root root Sep keyring-HcV70B
  5. srwxr-xr-x root root Sep mapping-root
  6. drwx------ root root Mar : vmware-root
  7. drwx------ root root Mar : ssh-WENobU7545
  8. srwxrwxrwx mysql mysql Mar : mysql3306.sock
  9. -rw-rw---- mysql mysql Mar : mysql3306.pid
  10. srwxrwxrwx mysql mysql Mar : mysql3307.sock
  11. -rw-rw---- mysql mysql Mar : mysql3307.pid
  12. srwxrwxrwx mysql mysql Mar : mysql3308.sock
  13. -rw-rw---- mysql mysql Mar : mysql3308.pid
  14. [root@ora11g tmp]# mysql -S mysql3306.sock
  15. Welcome to the MySQL monitor. Commands end with ; or \g.
  16. Your MySQL connection
  17. Server version: Source distribution
  18.  
  19. Copyright (c) , , Oracle and/or its affiliates. All rights reserved.
  20.  
  21. Oracle is a registered trademark of Oracle Corporation and/or its
  22. affiliates. Other names may be trademarks of their respective
  23. owners.
  24.  
  25. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  26.  
  27. mysql> grant shutdown on *.* to test@localhost identified by 'test' with grant option;
  28. Query OK, rows affected (0.00 sec)
  29.  
  30. mysql> show grants for test@localhost;
  31. +---------------------------------------------------------------+
  32. | Grants for test@localhost |
  33. +---------------------------------------------------------------+
  34. | GRANT SHUTDOWN ON *.* TO 'test'@'localhost' WITH GRANT OPTION |
  35. +---------------------------------------------------------------+
  36. row in set (0.01 sec)
  37.  
  38. 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. 如何区分SNAT和DNAT

    从定义来讲它们一个是源地址转换,一个是目标地址转换.都是地址转换的功能,将私有地址转换为公网地址.要区分这两个功能可以简单的由连接发起者是谁来区分:       内部地址要访问公网上的服务时(如web ...

  2. POJ 3009

    http://poj.org/problem?id=3009 一个搜索的题目: 大意就是一个冰球,在冰面上滑动,你打击一次,就沿一个反向滑动,知道碰到墙就会停下,而墙则会破碎. 求从起点到终点的最短的 ...

  3. mysql删除二进制日志文件

    一.RESET MASTER 这个语句可以验证首次配置主机备机是否成功.步骤如下: 1. 启动master和 slave,开启replication (即 复制) 注:replication (复制) ...

  4. glib-2.49.4 static build step in windows XP

    export LIBFFI_CFLAGS=" -I/usr/local/lib/libffi-3.2.1/include " \ export LIBFFI_LIBS=" ...

  5. hiho一下第二周 Trie树

    题目链接:http://hihocoder.com/problemset/problem/1014 #include <iostream> #include <cstdio> ...

  6. codeforces 507B. Amr and Pins 解题报告

    题目链接:http://codeforces.com/problemset/problem/507/B 题目意思:给出圆的半径,以及圆心坐标和最终圆心要到达的坐标位置.问最少步数是多少.移动见下图.( ...

  7. mybatis 的if else

    <update id="update" parameterType="XXX">         update XX set YY          ...

  8. Java常用工具类题库

    一.    填空题 在Java中每个Java基本类型在java.lang包中都在一个相应的包装类,把基本类型数据转换为对象,其中包装类Integer是___Number__的直接子类. 包装类Inte ...

  9. 地图API文档

    目录 腾讯地图API 2 1.API概览... 2 1.1 WebService API(官网注明是beta版本,可能不稳定,慎用):... 2 1.2 URL API:... 2 1.3 静态图AP ...

  10. java课后作业 弹出窗口求两个数的加减乘除

    //计算2个数的加减乘除 谷伟华 2015/10/6package jisuan; import javax.swing.JOptionPane; public class Jiasuan { pub ...