建站资讯

MySQL数据信息库新手入门多案例配备

作者:admin 发布时间:2021-04-03
WebjxCom提醒:前边详细介绍了有关的基本指令实际操作:MySQL数据信息库基本篇之新手入门基本指令全部的实际操作全是根据单案例的,mysql多案例在具体生产制造自然环境也是是非非常好用的,由于务必要把握。1、什么叫多案例多案例便是一台网络服务器上打开好几个不一样的服务端口号(默认设置3306),运作好几个mysql的服务过程,这此服
前边详细介绍了有关的基本指令实际操作:MySQL数据信息库基本篇之新手入门基本指令 全部的实际操作全是根据单案例的,mysql多案例在具体生产制造自然环境也是是非非常好用的,由于务必要把握。 1、什么叫多案例 多案例便是一台网络服务器上打开好几个不一样的服务端口号(默认设置3306),运作好几个mysql的服务过程,这此服务过程根据不一样的socket监视不一样的服务端口号来出示各在的服务,全部案例中间相互应用一套MYSQL的安裝程序,但各有应用不一样的配备文档、起动程序、数据信息文档,在逻辑性上是相对性单独的。 多案例关键功效是:充足运用目前的网络服务器硬件配置資源,为不一样的服务出示数据信息服务,可是假如某一案例高并发较为高的,一样是会危害到其他案例的特性 2、安裝多案例自然环境提前准备 安裝前必须先安裝mysql,可是只需将安裝全过程开展到make install就可以(编译程序安裝),假如应用免安裝程序,只需缓解压力手机软件包就可以,今日的自然环境是根据免安裝包来安裝mysql主程序(其他的安裝能够参照前边的安裝全过程自主检测) [ ~]# cat /etc/redhat-release CentOS release 6.5 (Final) [ ~]# uname -r 2.6.32-431.el6.x86_64 mysql-5.5.52-linux2.6-x86_64.tar.gz 最先将手机软件免费下载到当地 wget mysql/MySQL-5.5/mysql-5.5.52-linux2.6-x86_64.tar.gz 建立安裝客户 [ ~]#groupadd mysql [ ~]#useradd mysql -s /sbin/nologin -g mysql -M [ ~]#tail -1 /etc/passwd mysql:x:500:500::/home/mysql:/sbin/nologin 建立多案例的数据信息文件目录 []# mkdir -p /data/{3306,3307} []# tree /data/ /data/ +-- 3306 +-- 3307 2 directories, 0 files 3、安裝MYSQL多案例 接下去开展安裝mysql的多案例实际操作 []# ll mysql-5.5.52-linux2.6-x86_64.tar.gz -rw-r--r--. 1 root root Aug 26 21:38 mysql-5.5.52-linux2.6-x86_64.tar.gz []# tar zxf mysql-5.5.52-linux2.6-x86_64.tar.gz 复制配备文档 [-5.5.52-linux2.6-x86_64]# cp support-files/my-f /data/3306/f [-5.5.52-linux2.6-x86_64]# cp support-files/mysql.server /data/3306/mysql [-5.5.52-linux2.6-x86_64]# cp support-files/my-f /data/3307/f [-5.5.52-linux2.6-x86_64]# cp support-files/mysql.server /data/3307/mysql 为一标准安裝相对路径,将免安裝包复制到运用程序文件目录下 []# mv mysql-5.5.52-linux2.6-x86_64 /application/mysql []# ll /application/mysql total 72 drwxr-xr-x. 2 root root 4096 Dec 9 17:15 bin -rw-r--r--. 1 7 Aug 26 19:24 COPYING drwxr-xr-x. 3 root root 4096 Dec 9 17:15 data drwxr-xr-x. 2 root root 4096 Dec 9 17:15 docs drwxr-xr-x. 3 root root 4096 Dec 9 17:15 include -rw-r--r--. 1 7161 31415 301 Aug 26 19:24 INSTALL-BINARY drwxr-xr-x. 3 root root 4096 Dec 9 17:15 lib drwxr-xr-x. 4 root root 4096 Dec 9 17:15 man drwxr-xr-x. 10 root root 4096 Dec 9 17:15 mysql-test -rw-r--r--. 1 7 Aug 26 19:24 README drwxr-xr-x. 2 root root 4096 Dec 9 17:15 scripts drwxr-xr-x. 27 root root 4096 Dec 9 17:15 share drwxr-xr-x. 4 root root 4096 Dec 9 17:15 sql-bench drwxr-xr-x. 2 root root 4096 Dec 9 17:15 support-files 改动配备文档与起动文档 由于是多案例,在其中主要参数必须改动,改动后的配备文档以下:f [client] port = 3307 socket = /data/3307/mysql.sock [mysql] no-auto-rehash [mysqld] user = mysql port = 3307 socket = /data/3307/mysql.sock basedir = /application/mysql datadir = /data/3307/data #log_long_format #log-error = /data/3307/error.log #log-slow-queries = /data/3307/slow.log pid-file = /data/3307/mysql.pid server-id = 3 [mysqld_safe] log-error=/data/3307/mysql3307.err pid-file=/data/3307/mysqld.pid 起动程叙文件mysql []# cat mysql #!/bin/sh init port=3307 mysql_user="root" mysql_pwd="migongge" CmdPath="/application/mysql/bin" mysql_sock="/data/${port}/mysql.sock" #startup function_start_mysql() { if [ ! -e "$mysql_sock" ];then printf "Starting MySQL...\n" /bin/sh ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/f 2>&1 > /dev/null & printf "MySQL is running...\n" #stop function function_stop_mysql() { if [ ! -e "$mysql_sock" ];then printf "MySQL is stopped...\n" printf "Stoping MySQL...\n" ${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown #restart function function_restart_mysql() { printf "Restarting MySQL...\n" function_stop_mysql sleep 2 function_start_mysql case $1 in start) function_start_mysql stop) function_stop_mysql restart) function_restart_mysql printf "Usage: /data/${port}/mysql {start|stop|restart}\n" 其他的配备可参照配备文档开展改动就可以 多案例原始化实际操作 []# /application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data --user=mysql Installing MySQL system tables... 161209 18:02:17 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release. 161209 18:02:17 [Note] /application/mysql/bin/mysqld (mysqld 5.5.52-log) starting as process 3336 ... Filling help tables... 161209 18:02:17 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release. 161209 18:02:17 [Note] /application/mysql/bin/mysqld (mysqld 5.5.52-log) starting as process 3343 ... 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 mands: /application/mysql/bin/mysqladmin -u root password 'new-password' /application/mysql/bin/mysqladmin -u root -h centos6 password 'new-password' Alternatively you can run: /application/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 mended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd /application/mysql ; /application/mysql/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd /application/mysql/mysql-test ; perl mysql-test-run.pl Please report any problems at 原始化取得成功后,会在数据信息文件目录下造成一数量据文件目录data和一些文档 []# ll /data/3306/data/ total 1136 drwx------. 2 mysql root 4096 Dec 9 18:02 mysql -rw-rw----. 1 mysql mysql 27693 Dec 9 18:02 mysql-bin.000001 -rw-rw----. 1 mysql mysql 1114546 Dec 9 18:02 mysql-bin.000002 -rw-rw----. 1 mysql mysql 38 Dec 9 18:02 mysql-bin.index drwx------. 2 mysql mysql 4096 Dec 9 18:02 performance_schema drwx------. 2 mysql root 4096 Dec 9 18:02 test 另外一个案例的原始化请参照所述实际操作开展,实际操作全过程已不逐一详细介绍 []# ll /data/3307/data/ total 1136 drwx------. 2 mysql root 4096 Dec 9 18:40 mysql -rw-rw----. 1 mysql mysql 27693 Dec 9 18:40 mysql-bin.000001 -rw-rw----. 1 mysql mysql 1114546 Dec 9 18:40 mysql-bin.000002 -rw-rw----. 1 mysql mysql 38 Dec 9 18:40 mysql-bin.index drwx------. 2 mysql mysql 4096 Dec 9 18:40 performance_schema drwx------. 2 mysql root 4096 Dec 9 18:40 test 4 、起动多案例并登陆 []# /data/3306/mysql start Starting MySQL... []# lsof -i :3306 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME mysqld 19986 mysql 10u IPv4 90967 0t0 TCP *:mysql (LISTEN) []# /data/3307/mysql start Starting MySQL... []# lsof -i :3307 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME mysqld 21648 mysql 11u IPv4 92899 0t0 TCP *:opsession-prxy (LISTEN) []# netstat -lntup|grep mysql tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 21648/mysqld tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 19986/mysqld 登录多案例数据信息库 [ ~]# mysql -S /data/3306/mysql.sock Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.51-log Source distribution Copyright (c) 2000, 2016, 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> create database data3306; Query OK, 1 row affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | data3306 | | mysql | | performance_schema | | test | +--------------------+ 5 rows in set (0.00 sec) mysql> quit [ ~]# mysql -S /data/3307/mysql.sock Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.51 Source distribution Copyright (c) 2000, 2016, 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 | +--------------------+ 4 rows in set (0.05 sec) 取得成功登录,并在3306案例中建立数据信息库,可是3307案例上查询并沒有建立过的数据信息,表明2个案例是单独的 注:假如再必须增加一个案例,基本的配备流程跟上面一样述一样,只必须相对改动配备文档与起动程叙文件中的端口号号与数据信息文件目录的相对路径就可以,最终能够将多案例数据信息库起动指令添加启动开机启动。

收缩