mysql服务端与客户端的配置信息都在my.cnf文件中----- '/va
修改了mysql的数据文件目录为/home/mysql,安装时默认的数据文件目录为/var/lib/mysql,配置文件为/etc/my.cnf,更改/etc/init.d/mysql文件中的datadir=/home/mysql 。 我们要知道/etc/my.cnf配置文件中包含对mysql服务端和客户端的配置。 然后进行如下操作
修改了mysql的数据文件目录为/home/mysql,安装时默认的数据文件目录为/var/lib/mysql,配置文件为/etc/my.cnf,更改/etc/init.d/mysql文件中的datadir=/home/mysql 。
我们要知道/etc/my.cnf配置文件中包含对mysql服务端和客户端的配置。
然后进行如下操作,改名my.cnf为my.cnf-bak,更改/etc/init.d/mysql文件中的datadir为默认路径datadir=,然后启动mysql服务端/usr/bin/mysqld_safe --defaults-extra-file=/etc/my.cnf-bak,成功启动mysql服务端,查看mysqld、mysql进程信息ps -ef| grep -i mysql*,显示mysql的datadir为/home/mysql,sock为/home/mysql/mysql.sock,其他信息也显示正常,然后尝试登录mysql数据库,这时报错提示说/var/lib/mysql/mysql.sock不存在。为什么呢?是因为my.cnf配置文件不存在,mysql客户端没有找到配置文件,就会去读取安装mysql时rpm包编译时指定的默认路径,而/var/lib/mysql/mysql.sock不存在,所以报错。就是说这时mysql客户端从默认参数中读取的信息 与修改后的datadir=/home/mysql的信息不一致,所以无法登录mysql服务器
1)/etc/init.d/mysql里面的datadir=/home/mysql,在mysql启动文件里面设置了数据文件目录
2)查看/etc/、basedir、datadir、~./my.cnf下面是否存在my.cnf配置文件3)更改/etc/my.cnf为/etc/my.cnf-bak,mysql启动时会读取编译时设置的默认参数
4)此时可以正常启动mysql服务,因为在/etc/init.d/mysql中显示指定了数据文件的目录(似乎与第三条有点矛盾?其实3指的默认参数就是这里)
# service mysql start
# mysqladmin -uroot -p variables |grep -i basedir
# mysqladmin -uroot -p variables |grep -i datadir
5)现在修改/etc/init.d/mysql文件中的datadir,注释掉显示指定的datadir=/home/mysql
6)尝试关闭mysql数据库
#service mysql stop
#MySQL server PID file could not be found! [FAILED]
这是因为修改了mysql的datadir=/home/mysql,这时mysql会根据mysql的rpm包里面编译的默认路径/var/lib/mysql文件夹来读取PID文件,而/var/lib/mysql下面没有PID文件,所以提示。
7)此时可以通过mysqladmin -uroot -p shutdown 来正常关闭mysql进程。
8)因为/etc/my.cnf、basedir、datadir、~/.my.cnf都不存在,无法启动mysql。
可以通过/usr/bin/mysqld_safe --help查看mysqld_safe的参数,然后使用
# /usr/bin/mysqld_safe --defaults-extra-file=/etc/my.cnf-bak
指定mysql启动脚本,并启动mysqld进程。 这时mysqld_safe进程会占用终端(在当前终端,无法进行其他操作),使用Ctrl+Z停止mysqld进程(睡眠进程),再使用bg(fg将后台作业放到前台)把mysqld_safe进程设置为后台进程(会从睡眠状态恢复为运行状态,使用)。
###########
9)尝试连接mysql数据库,查看mysql的信息
# mysqladmin -uroot -p variables | grep -i datadir
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socke'/var/lib/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!
提示无法通过/var/lib/mysql/mysql.sock连接mysql服务器
尝试连接mysql数据库,
#mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
###########
查看mysql进程信息:
[root@localhost ~]# ps -ef|grep -i mysql*
root 18835 5614 0 04:10 pts/1 00:00:00 /bin/sh /usr/bin/mysqld_safe --defaults-extra-file=/etc/my.cnf-bak
mysql 19133 18835 0 04:10 pts/1 00:00:00 /usr/sbin/mysqld --defaults-extra-file=/etc/my.cnf-bak --basedir=/usr --datadir=/home/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/home/mysql/localhost.localdomain.err --pid-file=/home/mysql/localhost.localdomain.pid --socket=/home/mysql/mysql.sock --port=3306
这时会发现,mysql的进程信息显示的socket路径为修改过的my.cnf-bak中指定的路径/home/mysql/mysql.sock,而连接mysql数据库时,却说无法通过默认的socket路径连接/var/lib/mysql/mysql.sock连接。
############
这是由于/etc/my.cnf、basedir/my.cnf、datadir/my.cnf、~/.my.cnf文件都不存在,而在启动mysql服务的时候,使用/usr/bin/mysqld_safe --defaults-extra-file=/etc/my.cnf-bad 指定了启动时mysql_server读取的配置文件,这样mysql服务器进程成功启动,而在mysql_client客户端使用mysqladmin客户端工具、或mysql通过客户端尝试登陆mysql服务器 时,mysql客户端会去寻找my.cnf配置文件(my.cnf中包含了mysql服务端[mysqld]和客户端[client]的设置),因为没有找到my.cnf配置文件,无法读取用户的设置,mysql客户端会使用mysql安装时设置的默认目录,而默认数据文件目录/var/lib/mysql下没有mysql.sock,所以会报错说找不到/var/lib/mysql/mysql.sock。
my.cnf中的配置信息分类:
mysqld_safe / mysqld / mysqld_multi 属于服务器端配置
mysqldump / mysql / client / mysqladmin之类的属于客户端配置
[client]用户告诉客户端工具mysql连接数据库服务器使用的port和socket文件的路径
[mysql]用于设置客户端工具的显示信息,如在my.cnf中设置
[mysql]
#prompt="(\\u:hostname:\D)[\\d]> "
这样使用mysql -uroot -p连接到mysql服务器时,就会显示:
(root:hostname:Thu Feb 9 16:32:26 2012)[(none)]>

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

ToaddusersinMySQLeffectivelyandsecurely,followthesesteps:1)UsetheCREATEUSERstatementtoaddanewuser,specifyingthehostandastrongpassword.2)GrantnecessaryprivilegesusingtheGRANTstatement,adheringtotheprincipleofleastprivilege.3)Implementsecuritymeasuresl

ToaddanewuserwithcomplexpermissionsinMySQL,followthesesteps:1)CreatetheuserwithCREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';.2)Grantreadaccesstoalltablesin'mydatabase'withGRANTSELECTONmydatabase.TO'newuser'@'localhost';.3)Grantwriteaccessto'

The string data types in MySQL include CHAR, VARCHAR, BINARY, VARBINARY, BLOB, and TEXT. The collations determine the comparison and sorting of strings. 1.CHAR is suitable for fixed-length strings, VARCHAR is suitable for variable-length strings. 2.BINARY and VARBINARY are used for binary data, and BLOB and TEXT are used for large object data. 3. Sorting rules such as utf8mb4_unicode_ci ignores upper and lower case and is suitable for user names; utf8mb4_bin is case sensitive and is suitable for fields that require precise comparison.

The best MySQLVARCHAR column length selection should be based on data analysis, consider future growth, evaluate performance impacts, and character set requirements. 1) Analyze the data to determine typical lengths; 2) Reserve future expansion space; 3) Pay attention to the impact of large lengths on performance; 4) Consider the impact of character sets on storage. Through these steps, the efficiency and scalability of the database can be optimized.

MySQLBLOBshavelimits:TINYBLOB(255bytes),BLOB(65,535bytes),MEDIUMBLOB(16,777,215bytes),andLONGBLOB(4,294,967,295bytes).TouseBLOBseffectively:1)ConsiderperformanceimpactsandstorelargeBLOBsexternally;2)Managebackupsandreplicationcarefully;3)Usepathsinst

The best tools and technologies for automating the creation of users in MySQL include: 1. MySQLWorkbench, suitable for small to medium-sized environments, easy to use but high resource consumption; 2. Ansible, suitable for multi-server environments, simple but steep learning curve; 3. Custom Python scripts, flexible but need to ensure script security; 4. Puppet and Chef, suitable for large-scale environments, complex but scalable. Scale, learning curve and integration needs should be considered when choosing.

Yes,youcansearchinsideaBLOBinMySQLusingspecifictechniques.1)ConverttheBLOBtoaUTF-8stringwithCONVERTfunctionandsearchusingLIKE.2)ForcompressedBLOBs,useUNCOMPRESSbeforeconversion.3)Considerperformanceimpactsanddataencoding.4)Forcomplexdata,externalproc


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

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.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

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

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.

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