MYSQL 多实例运行 mysql可以以多实例的方式,实现一台服务器,运行在不同端口不同数据文件的mysql,它们是相互独立的。 1、关闭原有的默认端口3306的mysql:service mysqd stop 2、拷贝或创建数据文件 ? #拷贝现有的mysql数据库文件#我的在/var/lib/mysql,拷
MYSQL 多实例运行mysql可以以多实例的方式,实现一台服务器,运行在不同端口不同数据文件的mysql,它们是相互独立的。
1、关闭原有的默认端口3306的mysql:service mysqd stop
2、拷贝或创建数据文件
?
#拷贝现有的mysql数据库文件 #我的在/var/lib/mysql,拷贝一份至mysql_3307文件夹 [root@test-206 ~]# cp -r /var/lib/mysql /var/lib/mysql_3307
?
#创建一个新的空数据库 [root@test-206 ~]# mkdir /var/lib/mysql_3307 [root@test-206 ~]# mysql_install_db --datadir=/var/lib/mysql_3307 --user=mysql
?3、给数据文件赋予mysql用户与用户组
[root@test-206 ~]# chown -R mysql.mysql /var/lib/mysql_3307
?4、创建multi的配置cnf文件,用于启动这个mysql实例(如3307)载入执行
[root@test-206 ~]# touch /usr/local/my_multi.cnf
?文件中写入你想要的配置,如下为典型配置
[mysqld_multi] mysqld = /usr/bin/mysqld_safe mysqladmin = /usr/bin/mysqladmin user = root #用于登陆和关闭此服务 password = 123456 #同上 [mysqld3307] socket = /tmp/mysql_3307.sock port = 3307 pid-file = /var/lib/mysql_3307/3307.pid datadir = /var/lib/mysql_3307/ log = /var/lib/mysql_3307/3307.log character-set-server = utf8 user = mysql
?5、启动你的多实例
[root@test-206 ~]# mysqld_multi --defaults-extra-file=/usr/local/my_multi.cnf start 3307
?6、检查是否启动成功
[root@test-206 ~]# netstat -ntlp tcp 0 0 :::3306 :::* LISTEN 3919/mysqld tcp 0 0 :::3307 :::* LISTEN 15027/mysqld
?
如果没有发现你要的端口号mysql实例,可以检查下/var/lib/mysql_3307/3307.log文件,排除问题
7、设置新的密码
[root@test-206 ~]# mysqladmin -uroot -S /tmp/mysql_3307.sock password 123456
?8、登入你的新实例
[root@test-206 ~]# mysql -uroot -S /tmp/mysql_3307.sock -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.20-log Distributed by The IUS Community Project Copyright (c) 2000, 2011, 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>
?再次确认下,你的这个实例,是不是用的mysql_3307这个文件夹的数据
mysql> show variables like '%datadir%'; +---------------+----------------------+ | Variable_name | Value | +---------------+----------------------+ | datadir | /var/lib/mysql_3307/ | +---------------+----------------------+ row in set (0.00 sec) mysql>
?恩,没有错!最后,搞搞权限、用户之类。收工!
#查用户 mysql> select user,host from mysql.user; +------+-----------+ | user | host | +------+-----------+ | root | 127.0.0.1 | | root | ::1 | | | localhost | | root | localhost | | | test-206 | | root | test-206 | +------+-----------+ rows in set (0.00 sec) #设权限 mysql> grant all on *.* to root@'%' identified by 'root' with grant option; Query OK, 0 rows affected (0.00 sec) ##查权限 mysql> show grants for root; ##创用户 mysql> grant select on *.* to backup@'%' identified by 'backup'; Query OK, 0 rows affected (0.00 sec)
?

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

MySQloffersechar, Varchar, text, Anddenumforstringdata.usecharforfixed-Lengthstrings, VarcharerForvariable-Length, text forlarger text, AndenumforenforcingdataAntegritywithaetofvalues.

Optimizing MySQLBLOB requests can be done through the following strategies: 1. Reduce the frequency of BLOB query, use independent requests or delay loading; 2. Select the appropriate BLOB type (such as TINYBLOB); 3. Separate the BLOB data into separate tables; 4. Compress the BLOB data at the application layer; 5. Index the BLOB metadata. These methods can effectively improve performance by combining monitoring, caching and data sharding in actual applications.

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.


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

SublimeText3 Linux new version
SublimeText3 Linux latest version

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
