bitsCN.com
Linux下搭建MySQL多实例环境
前置条件:安装cmake工具、gcc工具
gcc一般的linux环境都已经安装,现在安装cmake
[root@localhost workspace]# wget http://www.cmake.org/files/v2.8/cmake-2.8.3.tar.gz
[root@localhost workspace]# tar xvf cmake-2.8.3.tar.gz
[root@localhost workspace]# cd cmake-2.8.3
[root@localhost workspace]# ./configure
[root@localhost workspace]# make & make install
下载mysql源码包
[root@localhost workspace]# wget http://downloads.mysql.com/archives/mysql-5.5/mysql-5.5.32.tar.gz
[root@localhost workspace]# tar xvf mysql-5.5.32.tar.gz
[root@localhost workspace]# cd mysql-5.5.32
安装第一个MySQL数据库
(1)创建所需要的文件目录
[root@localhost local]# cd /usr/local/
[root@localhost local]# mkdir mysql
[root@localhost local]# cd mysql/
[root@localhost mysql]# mkdir data
[root@localhost mysql]# mkdir etc
(2)配置MySQL源码编译选项
[root@localhost mysql-5.5.32]# cmake /
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql /
> -DMYSQL_DATADIR=/usr/local/mysql/data /
> -DSYSCONFDIR=/usr/local/mysql/etc /
> -DWITH_MYISAM_STORAGE_ENGINE=1 /
> -DWITH_INNOBASE_STORAGE_ENGINE=1 /
> -DWITH_MEMORY_STORAGE_ENGINE=1 /
> -DWITH_READLINE=1 /
> -DMYSQL_UNIX_ADDR=/tmp/mysqld.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
(3)编译安装
[root@localhost mysql-5.5.32]# make & make install
(4)配置第一个MySQL实例
[root@localhost mysql-5.5.32]# cd /usr/local/mysql
[root@localhost mysql]# chown -R mysql:mysql .
[root@localhost mysql]# cp support-files/my-medium.cnf /usr/local/mysql/etc/my.cnf
[root@localhost mysql]# vi /usr/local/mysql/etc/my.cnf
添加 datadir=/usr/local/mysql/data
default-storage-engine=MyISAM
[root@localhost mysql]# cd /usr/local/mysql/scripts/
[root@localhost scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data &
[root@localhost bin]# cd /usr/local/mysql/bin
[root@localhost bin]# ./mysqld_safe --user=root
[1] 28869
[root@localhost bin]# 131016 20:07:13 mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
131016 20:07:14 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
查看服务是否启动成功
[root@localhost bin]# netstat -tlnap | grep mysql
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 29147/mysqld
登录MySQL并修改root用户密码
[root@localhost bin]# ./mysqladmin -uroot password 'eisoo.com'
[root@localhost bin]# ./mysql -uroot -peisoo.com
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 2
Server version: 5.5.32-log Source distribution
Copyright (c) 2000, 2013, 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> exit
安装第二个MySQL数据库
(1)清理配置信息
[root@localhost bin]# cd /workspace/mysql-5.5.32
[root@localhost mysql-5.5.32]# make clean
[root@localhost mysql-5.5.32]# rm -rf CMakeCache.txt
(2)创建所需要的文件目录
[root@localhost mysql-5.5.32]# cd /usr/local/
[root@localhost local]# mkdir mysql3307
[root@localhost local]# cd mysql3307/
[root@localhost mysql3307]# mkdir data
[root@localhost mysql3307]# mkdir etc
(3)配置第二个实例的编译信息
[root@localhost bin]# cd /workspace/mysql-5.5.32
[root@localhost mysql-5.5.32]# cmake /
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql3307 /
> -DMYSQL_DATADIR=/usr/local/mysql3307/data /
> -DSYSCONFDIR=/usr/local/mysql3307/etc /
> -DWITH_MYISAM_STORAGE_ENGINE=1 /
> -DWITH_INNOBASE_STORAGE_ENGINE=1 /
> -DWITH_MEMORY_STORAGE_ENGINE=1 /
> -DWITH_READLINE=1 /
> -DMYSQL_UNIX_ADDR=/tmp/mysqld3307.sock /
> -DMYSQL_TCP_PORT=3307 /
> -DENABLED_LOCAL_INFILE=1 /
> -DWITH_PARTITION_STORAGE_ENGINE=1 /
> -DEXTRA_CHARSETS=all /
> -DDEFAULT_CHARSET=utf8 /
> -DDEFAULT_COLLATION=utf8_general_ci
(4)编译安装
[root@localhost mysql-5.5.32]# make & make install
(5)配置第二个MySQL实例
[root@localhost mysql-5.5.32]# cd /usr/local/mysql3307
[root@localhost mysql3307]# chown -R mysql:mysql .
[root@localhost mysql3307]# cp support-files/my-medium.cnf /usr/local/mysql3307/etc/my.cnf
[root@localhost mysql3307]# vi /usr/local/mysql3307/etc/my.cnf
添加 datadir=/usr/local/mysql3307/data
default-storage-engine=MyISAM
[root@localhost mysql3307]# cd /usr/local/mysql3307/scripts/
[root@localhost scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql3307 --datadir=/usr/local/mysql3307/data &
[root@localhost scripts]# cd /usr/local/mysql3307/bin
[root@localhost bin]# ./mysqld_safe --user=root
131016 20:40:27 mysqld_safe Logging to '/usr/local/mysql3307/data/localhost.localdomain.err'.
131016 20:40:27 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql3307/data
查看服务是否启动成功
[root@localhost bin]# netstat -tlnap | grep mysql
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 29147/mysqld
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 7447/mysqld
登录MySQL并修改root用户密码
[root@localhost bin]# ./mysqladmin -uroot password 'eisoo.com123'
[root@localhost bin]# ./mysql -uroot -peisoo.com123
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 2
Server version: 5.5.32-log Source distribution
Copyright (c) 2000, 2013, 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> exit
增加系统环境变量
[root@localhost /]# vi /etc/profile
增加一行:export PATH=/usr/local/mysql/bin:/usr/local/mysql3307/bin:$PATH
[root@localhost /]# source /etc/profile
[root@localhost /]# export $PATH
分别启动不同实例:
[root@localhost /]# mysqld_safe --user=root --port=3306 --socket=/tmp/mysqld.sock --datadir=/usr/local/mysql/data &
[root@localhost /]# mysqld_safe --user=root --port=3307 --socket=/tmp/mysqld3307.sock --datadir=/usr/local/mysql3307/data &
分别登陆不同实例:
[root@localhost /]# mysql -uroot -peisoo.com -S /tmp/mysqld.sock
[root@localhost /]# mysql -uroot -peisoo.com123 -S /tmp/mysqld3307.sock
启动还是太麻烦,可以这样做:
[root@localhost /]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql3306
[root@localhost /]# cp /usr/local/mysql3307/support-files/mysql.server /etc/init.d/mysql3307
给mysql用户添加权限:
[root@localhost /]# chmod -R 755 /usr/local/mysql/data
[root@localhost /]# chmod -R 755 /usr/local/mysql/data
分别启动实例对应的服务:
[root@localhost tmp]# service mysql3306 start
Starting MySQL. [确定]
[root@localhost tmp]# service mysql3307 start
Starting MySQL. [确定]
查看服务:
[root@localhost tmp]# netstat -tlnap | grep mysql
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 10759/mysqld
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 11097/mysqld
将服务添加到系统服务中,使其开机自动启动。
[root@localhost /]# chkconfig --add mysql3306
[root@localhost /]# chkconfig --add mysql3307
bitsCN.com

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
