使用mysql基本基本上会遇到主要的两个问题.1.第一次起动mysql是没有问题的.对mysql做了一些操作,特别是删除mysql中一些不要的帐号
使用mysql基本基本上会遇到主要的两个问题.
1.第一次起动mysql是没有问题的.对mysql做了一些操作,特别是删除mysql中一些不要的帐号后,重新起动mysql会遇到这样的问题
#/etc/init.d/mysqld restart
stopping mysql [ok]
Timeout error occurred trying to start MySQL Daemon. [failure]
但是这个时候mysql实际上已经起动了,因为用netstat -ln命令去看3306端口已经起动.使用mysql -u root -p password也能连接到数据库.
这实际上是mysql-3.x的一个bug(具体可以去看mysql的bugzilla和RedHat的bugzilla).
是什么原因导致连接超时呢?
我们不妨先看看/etc/init.d/mysqld起动脚本是如何工作的,注意下面的一段
# If you've removed anonymous users, this line must be changed to
# use a user that is allowed to ping mysqld.
ping="/usr/bin/mysqladmin -uUNKNOWN_MYSQL_USER ping"
# Spin for a maximum of ten seconds waiting for the server to come up
if [ $ret -eq 0 ]; then
for x in 1 2 3 4 5 6 7 8 9 10; do
if [ -n "`$ping 2> /dev/null`" ]; then
break;
else
sleep 1;
fi
done
if !([ -n "`$ping 2> /dev/null`" ]); then
echo "Timeout error occurred trying to start MySQL
Daemon." action $"Starting $prog: " /bin/false
else
action $"Starting $prog: " /bin/true
fi
else
action $"Starting $prog: " /bin/false
fi
[ $ret -eq 0 ] && touch /var/lock/subsys/mysqld
return $ret
我们看到,脚本判断mysql是否起动,使用的是mysqladmin ping命令.
而这个命令想要正确执行是需要能够登录mysql的.现在一些默认帐号已经删除,而且其它帐号已经设置了密码(默认没有设置密码).于是它没有办法连接到mysql.
不妨使用下面的命令测试一下
#mysqladmin -u root -ppassword ping
mysql alive
当你提供了帐号和密码时,它的ping命令就可以正确执行了.
这个bug在mysql新出的mysql4.x可以解决.
但是RH9到FC3一直使用的是mysql3.x(不过mysql官方好象才推出mysql4.1,FC需要考虑问题性).
于是我用了下面的办法临时解决.
a)建立一个帐号,不设置密码,不给任何权限.
b)修改/etc/init.d/mysqld
下面我给出具体操作
#mysql -u root -p passwd
mysql>GRANT select ON test.* TO daemon@localhost
mysql>revoke select on test.* from daemon@localhost
打开/etc/init.d/mysqld
把下面这行
ping="/usr/bin/mysqladmin -uUNKNOWN_MYSQL_USER ping"
修改为
ping="/usr/bin/mysqladmin -udaemon ping"
保存,退出.
重新起动mysql
#/etc/init.d/mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
如果你的第二行仍然是failure的话.再执行下面的命令
#/etc/init.d/mysqld start
这时应该式ok了.
如果这样可以ok的话.
那么你需要修改/etc/init.d/mysqld,
在restart函数的start后面再加一个start就可了.
2.即使刚安装的mysql再起动后,去看日志,给给出下面的这些信息
Cannot initialize InnoDB as 'innodb_data_file_path' is not set.
If you do not want to use transactional InnoDB tables, add a line
skip-innodb
to the [mysqld] section of init parameters in your my.cnf
or my.ini. If you want to use InnoDB tables, add to the [mysqld]
section, for example,
innodb_data_file_path = ibdata1:10M:autoextend
But to get good performance you should adjust for your hardware
the InnoDB startup options listed in section 2 at
这是因为默认的数据库起动脚本需要加载innodb数据库,但是mysql在做初始话时并没有初始化时,并没有加载这样的数据库.
因此这里有两种解决办法:使用和不使用innodb.
我们先看不使用innodb的办法.
其实这个方法就是跳过innodb的方法.
在/etc/my.cnf文件的mysqld区域增加一行
skip-innodb就可以了.
如果我们需要使用innodb呢?
那么可在/etc/my.cnf文件的mysqld区域增加下面几行
innodb_data_home_dir = /var/lib/mysql/
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /var/lib/mysql/
innodb_log_arch_dir = /var/lib/mysql/
set-variable = innodb_buffer_pool_size=16M
set-variable = innodb_additional_mem_pool_size=2M
set-variable = innodb_log_file_size=5M
set-variable = innodb_log_buffer_size=8M
innodb_flush_log_at_trx_commit=1
set-variable = innodb_lock_wait_timeout=50
保存,退出.重启起动mysql,再去看日志.
应该不会再提示有关innodb的问题了.

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

Key metrics for EXPLAIN commands include type, key, rows, and Extra. 1) The type reflects the access type of the query. The higher the value, the higher the efficiency, such as const is better than ALL. 2) The key displays the index used, and NULL indicates no index. 3) rows estimates the number of scanned rows, affecting query performance. 4) Extra provides additional information, such as Usingfilesort prompts that it needs to be optimized.

Usingtemporary indicates that the need to create temporary tables in MySQL queries, which are commonly found in ORDERBY using DISTINCT, GROUPBY, or non-indexed columns. You can avoid the occurrence of indexes and rewrite queries and improve query performance. Specifically, when Usingtemporary appears in EXPLAIN output, it means that MySQL needs to create temporary tables to handle queries. This usually occurs when: 1) deduplication or grouping when using DISTINCT or GROUPBY; 2) sort when ORDERBY contains non-index columns; 3) use complex subquery or join operations. Optimization methods include: 1) ORDERBY and GROUPB

MySQL/InnoDB supports four transaction isolation levels: ReadUncommitted, ReadCommitted, RepeatableRead and Serializable. 1.ReadUncommitted allows reading of uncommitted data, which may cause dirty reading. 2. ReadCommitted avoids dirty reading, but non-repeatable reading may occur. 3.RepeatableRead is the default level, avoiding dirty reading and non-repeatable reading, but phantom reading may occur. 4. Serializable avoids all concurrency problems but reduces concurrency. Choosing the appropriate isolation level requires balancing data consistency and performance requirements.

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

The MySQL learning path includes basic knowledge, core concepts, usage examples, and optimization techniques. 1) Understand basic concepts such as tables, rows, columns, and SQL queries. 2) Learn the definition, working principles and advantages of MySQL. 3) Master basic CRUD operations and advanced usage, such as indexes and stored procedures. 4) Familiar with common error debugging and performance optimization suggestions, such as rational use of indexes and optimization queries. Through these steps, you will have a full grasp of the use and optimization of MySQL.

MySQL's real-world applications include basic database design and complex query optimization. 1) Basic usage: used to store and manage user data, such as inserting, querying, updating and deleting user information. 2) Advanced usage: Handle complex business logic, such as order and inventory management of e-commerce platforms. 3) Performance optimization: Improve performance by rationally using indexes, partition tables and query caches.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

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

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment