bitsCN.com
mysql二进制非root用户安装后启动mysqld的路径不对的问题 一、非root用户安装二进制mysql分发版 创建用户 >useradd fc >passwd fc enter password:...以fc登录,上传二进制mysql版本,我的是mysql 32位的mysql-5.1.57-linux-i686-glibc23.tar.gz 解压后,创建权限表 ]$ scripts/mysql_install_db --basedir=/home/fc/app/mysql --datadir=/home/fc/app/mysql/data/3307 --user=fc (注意:后面的参数一定要指定 ,另外最好是 scripts/mysql_install_db 这样一起运行,官方文档也是这样,免得出错,后面就有这个原因导致启动出错的) 权限表也初始化完了,然后就是指定配置文件my.cnf 我放在$HOME目录下:
[python] # Example MySQL config file for medium systems. # # This is for a system with little memory (32M - 64M) where MySQL plays # an important part, or systems up to 128M where MySQL is used together with # other programs (such as a web server) # # MySQL programs look for option files in a set of # locations which depend on the deployment platform. # You can copy this option file to one of those # locations. For information about these locations, see: # http://dev.mysql.com/doc/mysql/en/option-files.html # # In this file, you can use all long options that a program supports. # If you want to know which options a program supports, run the program # with the "--help" option. # The following options will be passed to all MySQL clients [client] #password = your_password port = 3307 socket = /home/fc/app/mysql/tmp/3307/mysql.sock # Here follows entries for some specific programs # The MySQL server [mysqld] character-set-server = utf8 port = 3307 socket = /home/fc/app/mysql/tmp/3307/mysql.sock skip-external-locking basedir = /home/fc/app/mysql datadir = /home/fc/app/mysql/data/3307/ log-error = /home/fc/log/3307/mysqld.err pid-file = /home/fc/app/mysql/tmp/3307/mysql.pid key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M max_connections=200 slow_query_log = 1 #{0|1 off|on} slow_query_log_file = /home/fc/log/3307/mysql-slow.log long_query_time=1 #不经常更新的表查询,缓存查询 query_cache_type = 1 query_cache_size = 10M general_log = 0 general_log_file = /home/fc/log/3307/mysql.log query_cache_size = 8M #skip-networking skip-name-resolve skip-innodb-checksums # Replication Master Server (default) # binary logging is required for replication log-bin=/home/fc/log/3307/mysql-bin # binary logging format - mixed recommended binlog_format=mixed binlog_cache_size = 1M max_binlog_cache_size = 4096M expire-logs-days = 8 sync_binlog=20 # Uncomment the following if you are using InnoDB tables innodb_data_home_dir = /home/fc/data/3307/ innodb_data_file_path = ibdata1:10M:autoextend innodb_log_group_home_dir = /home/fc/data/3307/ innodb_buffer_pool_size = 800M sort_buffer_size = 5M tmp_table_size = 64M innodb_additional_mem_pool_size = 32M innodb_autoextend_increment = 64 # 默认单位为 MB innodb_thread_concurrency = 8 innodb_log_file_size = 200M innodb_log_buffer_size = 8M default-storage-engine=innodb innodb_flush_log_at_trx_commit = 1 # Set .._log_file_size to 25 % of buffer pool size #innodb_log_file_size = 5M #innodb_log_buffer_size = 8M #innodb_flush_log_at_trx_commit = 1 #innodb_lock_wait_timeout = 50 innodb_flush_log_at_trx_commit = 2 [mysqldump] quick max_allowed_packet = 16M [mysqld_safe] log-error=/home/fc/app/mysql/log/3307/mysqld.log pid-file=/home/fc/app/mysql/tmp/3307/mysql.pid [mysql] no-auto-rehash port = 3307 socket = /home/fc/app/mysql/tmp/3307/mysql.sock # Remove the next comment character if you are not familiar with SQL #safe-updates [myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout 好了,一切都准备好了,可以启动了二、启动mysqld进程进入basedir目录fc/app/mysqlmysql]$ cd binbin]$ mysqld_safe --defaults-file=~/my.cnf &启动成功了,查看进程 ps -ef | grep mysqld 发现问题了[plain] fc 7780 7582 24 16:42 pts/10 00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=~/my.cnf --basedir=/home/fc/app/mysql --datadir=/home/fc/app/mysql/data/3307/ --log-error=/home/fc/app/mysql/log/3307/mysqld.log --pid-file=/home/fc/app/mysql/tmp/3307/mysql.pid --socket=/home/fc/app/mysql/tmp/3307/mysql.sock --port=3307 发现没有,虽然进入的fc/app/mysql/bin目录下启动的mysqld程序,但是查找进程时候却是运行的/usr/lcoal/mysql下的mysqld,这是为什么呢?查找了很久的参数,都发现没有配置错误,始终不得其解,如是换了种启动方式:进入base目录fc/app/mysql mysql]$ bin/msyqld_safe --defaults-file=~/my.cnf &这样启动后再查找mysqld进程,一切就正常了,这是为什么呢? 我自己想的原因可能是:mysqld_safe本身就是mysqld的守护进程,它本身也是一个shell脚本,在脚本中,默认的basedir就是:usr/local/mysql,我们在启动mysqld的时候如果进入了bin目录,则在这个守护进程中是找不到该目录的,如是就去自动匹配/usr/local/mysql/这个目录,刚好我也在这个目录之前装过mysql,于是系统就自动匹配了这个mysqld程序,运行起来了。 我们查看下mysqld_safe的一段shell代码:[python] MY_PWD=`pwd` # Check for the directories we would expect from a binary release install if test -n "$MY_BASEDIR_VERSION" -a -d "$MY_BASEDIR_VERSION" then # BASEDIR is already overridden on command line. Do not re-set. # Use BASEDIR to discover le. if test -x "$MY_BASEDIR_VERSION/libexec/mysqld" then ledir="$MY_BASEDIR_VERSION/libexec" elif test -x "$MY_BASEDIR_VERSION/sbin/mysqld" then ledir="$MY_BASEDIR_VERSION/sbin" else ledir="$MY_BASEDIR_VERSION/bin" fi elif test -f "$relpkgdata"/english/errmsg.sys -a -x "$MY_PWD/bin/mysqld" then MY_BASEDIR_VERSION="$MY_PWD" # Where bin, share and data are ledir="$MY_PWD/bin" # Where mysqld is # Check for the directories we would expect from a source install elif test -f "$relpkgdata"/english/errmsg.sys -a -x "$MY_PWD/libexec/mysqld" then MY_BASEDIR_VERSION="$MY_PWD" # Where libexec, share and var are ledir="$MY_PWD/libexec" # Where mysqld is elif test -f "$relpkgdata"/english/errmsg.sys -a -x "$MY_PWD/sbin/mysqld" then MY_BASEDIR_VERSION="$MY_PWD" # Where sbin, share and var are ledir="$MY_PWD/sbin" # Where mysqld is # Since we didn't find anything, used the compiled-in defaults else MY_BASEDIR_VERSION='/usr/local/mysql' ledir='/usr/local/mysql/bin' fi 如果我们进入了bin目录:ledir 跑到 elseMY_BASEDIR_VERSION='/usr/local/mysql'ledir='/usr/local/mysql/bin'正常的情况下应该是:"$MY_PWD/bin/mysqld" 问题是没有cd到 mysql basedir 的情况下,mysql会从/usr/loca/mysql/bin/mysqld启动 PS:附连接的问题 由于我们启动是按照socket启动的,所以我们在连接时候如果使用的是localhost或者缺省的状态去连接mysql,则我们连接必须使用指定的socket全路径去连接。不然系统会默认的去寻找/tmp/mysql.socket这个,找不到则报错;当然我们还可以使用-h 127.0.0.1 的方式来连接,这样就不需要指定 -S socket路径了; mysql连接的方式有2种,一种是通过socket,一种是通过tcp/ip连接[plain]

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.

ToaddauserremotelytoMySQL,followthesesteps:1)ConnecttoMySQLasroot,2)Createanewuserwithremoteaccess,3)Grantnecessaryprivileges,and4)Flushprivileges.BecautiousofsecurityrisksbylimitingprivilegesandaccesstospecificIPs,ensuringstrongpasswords,andmonitori

TostorestringsefficientlyinMySQL,choosetherightdatatypebasedonyourneeds:1)UseCHARforfixed-lengthstringslikecountrycodes.2)UseVARCHARforvariable-lengthstringslikenames.3)UseTEXTforlong-formtextcontent.4)UseBLOBforbinarydatalikeimages.Considerstorageov

When selecting MySQL's BLOB and TEXT data types, BLOB is suitable for storing binary data, and TEXT is suitable for storing text data. 1) BLOB is suitable for binary data such as pictures and audio, 2) TEXT is suitable for text data such as articles and comments. When choosing, data properties and performance optimization must be considered.

No,youshouldnotusetherootuserinMySQLforyourproduct.Instead,createspecificuserswithlimitedprivilegestoenhancesecurityandperformance:1)Createanewuserwithastrongpassword,2)Grantonlynecessarypermissionstothisuser,3)Regularlyreviewandupdateuserpermissions

MySQLstringdatatypesshouldbechosenbasedondatacharacteristicsandusecases:1)UseCHARforfixed-lengthstringslikecountrycodes.2)UseVARCHARforvariable-lengthstringslikenames.3)UseBINARYorVARBINARYforbinarydatalikecryptographickeys.4)UseBLOBorTEXTforlargeuns


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

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version
Recommended: Win version, supports code prompts!

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

Dreamweaver Mac version
Visual web development 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.
