您的位置:首页 > 运维架构 > Linux

linux下安装Mysq的各种bug的总结及解决办法

2014-07-08 16:59 288 查看
下载mysql安装包

groupadd mysql
useradd -g mysql mysql -s /sbin/nologin -M
tar -xvzf mysql-5.1.59.tar.gz -C /usr/local/src/
cd /usr/local/src/mysql-5.1.59

./configure --prefix=/usr/local/mysql --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobase --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static 

make&&make install 

cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
cd /usr/local/mysql
chown -R mysql .
chgrp -R mysql .
bin/mysql_install_db --user=mysql --skip-external-locking
chown -R root .
chown -R mysql var
bin/mysqld_safe --user=mysql &

export PATH=$PATH:/usr/local/mysql/bin/

/usr/local/mysql/bin/mysql_secure_installation

安装 cmake 编译器。1)、下载cmake
#cd /usr/local/src
#wget http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz 2)、解压cmake
#tar -zvxf cmake-2.8.4.tar.gz 
3)、配置编译
#cd cmake-2.8.4
#yum -y install gcc
#yum -y install gcc-c++
#yum -y install ncurses-devel
#./configure
#make
#make install
2、安装MySQL
1)、下载MySQL。
#cd /usr/local/src
#wget http://sdk.ruiya.com/linux/mysql-5.5.9.tar.gz 2)、添加必要的组和拥有者
#groupadd mysql
#useradd -r -g mysql mysql
3)、解压MySQL
#tar -zvxf mysql-5.5.9.tar.gz
4)、配置编译
如果是重装MySql,请先删除my.cnf如: rm -rf /etc/my.cnf
#mkdir /usr/local/mysql
#mkdir /usr/local/mysql/data
#cd /usr/local/src/mysql-5.5.9
#cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DINSTALL_DATADIR=/usr/local/mysql/data \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DENABLED_LOCAL_INFILE=1
参数说明:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql        //安装目录
-DINSTALL_DATADIR=/usr/local/mysql/data         //数据库存放目录
-DDEFAULT_CHARSET=utf8                        //使用utf8字符
-DDEFAULT_COLLATION=utf8_general_ci            //校验字符
-DEXTRA_CHARSETS=all                            //安装所有扩展字符集
-DENABLED_LOCAL_INFILE=1                        //允许从本地导入数据
#make
#make install
注意事项:
重新编译时,需要清除旧的对象文件和缓存信息。 
# make clean
# rm -f  CMakeCache.txt
# rm -rf /etc/my.cnf 
4)、设置目录权限
# cd /usr/local/mysql
# chown -R root:mysql . //把当前目录中所有文件的所有者所有者设为root,所属组为mysql
# chown -R mysql:mysql data
 
5)、配置文件
# cp support-files/my-medium.cnf /etc/my.cnf //这个配置仅适合小内存系统(32M - 64M)
打开如下注释:
innodb_data_home_dir = /usr/local/mysql/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /usr/local/mysql/data
innodb_buffer_pool_size = 16M
innodb_additional_mem_pool_size = 2M
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
添加默认字符集:
[client] 
default-character-set = utf8    // 添加编码支持
[mysqld]
default-character-set = utf8   // 添加编码支持
max_connections = 10000     //根据服务器性能调节
basedir = /usr/local/mysql //设置安装目录,这样在系统启动时才能正确运行到/etc/rc.d/init.d/mysql start
6)、创建系统数据库的表
# cd /usr/local/mysql
# scripts/mysql_install_db --user=mysql

7)、设置权限启动
设置环境变量:
# vi /root/.bash_profile
在PATH=$PATH:$HOME/bin添加参数为:
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib
#source /root/.bash_profile
手动启动MySQL: 
# cd /usr/local/mysql
# ./bin/mysqld_safe --user=mysql &   //启动MySQL,但不能停止
启动日志写在此文件下:/usr/local/mysql/data/localhost.err
关闭MySQL服务
# mysqladmin -u root -p shutdown  //这里MySQL的root用户还没有配置密码,所以为空值。
通过脚本启动MySQL:
# ln -s /usr/local/mysql/support-files/mysql.server /usr/local/mysql
//必须注意,是放在mysql目录下,不是bin目录下
# cp /usr/local/mysql/support-files/mysql.server /usr/local/mysql  
# mysql.server start //启动mysql
# mysql.server stop //停止mysql
在引导时启动MySQL :
# ln -s /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql
# ln -s /usr/local/mysql/mysql.server /etc/rc.d/init.d/mysql 
# cd /etc/rc.d/init.d
# chkconfig --add mysql       //配置是否自动启动, chkconfig --del mysql 可删除
# chmod +x /etc/rc.d/init.d/mysql    //添加如执行权限




Tips[code]Linux运行级别:
分成了8种运行级别,其中常用7种。可在/etc/inittab文件中设置。
0 - halt
1 - Single user mode
2 - Multiuser, without NFS
3 - Full multiuser mode
4 - unused
5 - x11
6 - reboot
默认设置为:id:3:initdefault:
每一种动行级别都有自已独立的文件夹,例如:
/etc/rc.d/rc3.d 表示运行级别为3的配置都存放在这个文件侠中。

# chkconfig --list |grep mysql      //检查看是否设置为自启动
mysql           0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭
表示: 运行级别2、3、4、5都会自动启动mysql


另一种手动配置自已启动
可能会出现这种情况,如果你试图在/etc/rc.d/rc3.d目录下运行../init.d/mysql start可能会收到如下错误
Starting MySQLCouldn't find MySQL server (./bin/mysqld_safe[失败]
可见mysql.server内部引用了一个相对路径./bin/mysqld_safe,所以这样就导致失败。
这样我们可以直接在rc.local文件中添加启动脚本:
# chkconfig --del mysql
# cd /etc/rc.d
# vi rc.local //添加: /usr/local/mysql/bin/mysqld_safe --user=mysql &
解决办法:在/etc/my.cnf 配置文件中添加:

basedir = /usr/local/mysql
8)、修改MySQL的root用户的密码
# mysql -u root mysql
mysql>use mysql;
mysql>desc user;
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";  //为root添加远程连接的能力。
mysql>update user set Password = password('xxxxxx') where User='root';
mysql>select Host,User,Password from user where User='root';
mysql>flush privileges;
mysql>exit
重新登录:mysql -u root -p
9)、添加软链接
# ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
# ln -s /usr/local/mysql/include/mysql /usr/include/mysql
注意事项:
<1>、MySQL5.5 默认使用InnoDB作为存储引擎,所以可以不设置DWITH_MYISAM_STORAGE_ENGINE值
参考:
如何打开MySQL中root账户的远程登录
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";
注意%对应的密码,如果不相同,可以通过 update user set Password = password('xxxxxx') where User='root'; 修改。
同时注意防火墙是否已关闭或者添加例外。
# /etc/rc.d/init.d/iptables stop
关闭或开启Linux/CentOS上的防火墙
导出数据库生成SQL脚本
mysqldump -h 192.168.200.18 -u root -p TestDB > TestDB.sql
<2>、测试mysql守护进程。
#cd /usr/local/mysql/mysql-test ;
#perl mysql-test-run.pl
<3>、注意事项:


To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h localhost password 'new-password'

Alternatively you can run:
/usr/local/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/local/mysql/scripts/mysqlbug script!

MySQL: Starting MySQL….. ERROR! The server quit without updating PID file解决办法

1 问题[root@localhost mysql]# /etc/rc.d/init.d/mysql status
MySQL is not running, but lock file (/var/lock/subsys/mysql[FAILED]
[root@localhost mysql]# /etc/rc.d/init.d/mysql start
Starting MySQL...The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).                              [FAILED] 2 原因没有初始化权限表 3 解决办法#cd /usr/local/mysql(进入mysql安装目录)
#chown -R mysql.mysql .
#su - mysql
$cd server
$scripts/mysql_install_db 4 本人解决过程[root@localhost ~]# cd /usr/local/mysql[root@localhost mysql]# chown -R mysql.mysql .
[root@localhost mysql]# su - mysql
[mysql@localhost ~]$ cd /usr/local/mysql
[mysql@localhost mysql]$ scripts/mysql_install_db
Installing MySQL system tables...
OK
Filling help tables...
OKTo start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h localhost.localdomain password 'new-password'Alternatively you can run:
./bin/mysql_secure_installationwhich will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with:
cd . ; ./bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.plPlease report any problems with the ./bin/mysqlbug script![mysql@localhost mysql]$ /usr/local/mysql/bin/mysqld_safe --user=mysql &
[1] 11767
[mysql@localhost mysql]$ 120502 07:01:17 mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
120502 07:01:17 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
[mysql@localhost mysql]$ /etc/rc.d/init.d/mysql status
MySQL running (11830)                                      [  OK  ]
[mysql@localhost mysql]$ /etc/rc.d/init.d/mysql start
Starting MySQL                                             [  OK  ]
  

附一文:MySQL: Starting MySQL….. ERROR! The server quit without updating PID file

FROM:http://icesquare.com/wordpress/mysql-starting-mysql-error-the-server-quit-without-updating-pid-file/ This step-by-step guide is mainly for FreeBSD, however the idea is the same for Linux. Every once a while, when I update my FreeBSD box, the system likes to shutdown my MySQL server. Therefore, I need to start it again after the update is done. Unfortunately, the upgrade process is not smooth every time. Sometimes it will throw me some error./usr/local/etc/rc.d/mysql.server start
Oh well, I got the following error messages:Starting MySQL..... ERROR! The server quit without updating PID file.[/code]Sometimes, the message will tell you the exact location of which PID file:
Starting MySQL..... ERROR! The server quit without updating PID file (/var/db/mysql/www.icesquare.com.pid).
There are several solutions to troubleshoot these problems. I will go over each one by one.

Solution 1: Reboot The Computer

Although it sounds simple, but it really works. During the system upgrade, the OS may disable some of your daemons. Instead of troubleshooting each one by one, the easiest way is to start everything over. For example, I experienced this problem today after upgrading the Apache and Ruby (Yes, MySQL is not part of the update), and I got this error message afterward. After rebooting the computer, the error message is gone.

Solution 2: Remove Your MySQL Config File

If you have modified your MySQL configuration file, MySQL may not like it few versions after (MySQL is not backward compatibility friendly). It can be the problem of using an unsupported variable, or something similar. The easiest way is to remove your configuration file, and try to start the MySQL server again:Backup your MySQL configuration first.
mv /etc/my.cnf /etc/my.cnf.backup
And restart the MySQL server again:
/usr/local/share/mysql/mysql.server start
Hopefully you will see the following message:
Starting MySQL. SUCCESS!

Solution 3: Upgrade Your Database File

Sometimes, the newer MySQL doesn’t like the database created in earlier version. I discovered this when I upgrade to MySQL 5.5.7:
Starting MySQL..... ERROR! The server quit without updating PID file (/var/db/mysql/www.icesquare.com.pid).
Since MySQL tells me which PID file causes the problem, I open the file and take a look what’s going on:
sudo tail /var/db/mysql/www.icesquare.com.err
And I saw something interesting: tables: Table ‘mysql.proxies_priv’ doesn’t exist:
101112 10:49:16 InnoDB: Initializing buffer pool, size = 128.0M 101112 10:49:16 InnoDB: Completed initialization of buffer pool 101112 10:49:16 InnoDB: highest supported file format is Barracuda. 101112 10:49:17 InnoDB: 1.1.3 started; log sequence number 1589404 101112 10:49:17 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.proxies_priv' doesn't exist 101112 10:49:17 mysqld_safe mysqld from pid file /var/db/mysql/www.icesquare.com.pid ended
The reason is very simple. MySQL could not open a table created in the earlier version (< 5.7.7) because it is not compatible with the current version. So, we can try to start the MySQL in safe mode through rc.d. First, you can edit the /etc/rc.conf and put the following into the file:
mysql_enable="YES" mysql_args="--skip-grant-tables --skip-networking"
Restart MySQL through rc.d:
/usr/local/etc/rc.d/mysql-server start
If you did it right, you should see something like the following:
Starting MySQL.. SUCCESS!
Now, MySQL is already running the safe-mode. We want to perform a MySQL upgrade on all tables:
sudo mysql_upgrade
You should see something like this:
Looking for 'mysql' as: mysql Looking for 'mysqlcheck' as: mysqlcheck Running 'mysqlcheck' with connection arguments: '--port=3306' '--socket=/tmp/mysql.sock' Running 'mysqlcheck' with connection arguments: '--port=3306' '--socket=/tmp/mysql.sock' mysql.columns_priv OK mysql.db OK mysql.event OK mysql.func OK mysql.general_log OK mysql.help_category OK mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.host OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.servers OK mysql.slow_log OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK mysql.time_zone_name OK mysql.time_zone_transition OK mysql.time_zone_transition_type OK mysql.user OK Running 'mysql_fix_privilege_tables'... OK
Now, we want to switch the MySQL back to normal mode by commenting the extra options in /etc/rc.conf:
mysql_enable="YES" #mysql_args="--skip-grant-tables --skip-networking"
And restart MySQL through /etc/rc.d:
/usr/local/etc/rc.d/mysql-server restart
Now the MySQL is up and running again!Happy MySQLing.–Derrick


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐