---
title: "ubantu下安装mysql小记"
author: "vieri124"
date: "2011-05-25T11:08:57Z"
tags: []
categories: ["数据库"]
slug: "ubantu-mysql"
draft: false
lastmod: "2011-05-25T11:14:49Z"
id: 1057965
url: "https://vieri124.iteye.com/blog/1057965"
---

下载最新的mysql二进制版本,查看包下的文件  
\[root@my-desktop]# tar -tvf MySQL-5.5.10-1.linux2.6.i386.tar  
解压  
\[root@my-desktop]# tar -xvf MySQL-5.5.10-1.linux2.6.i386.tar  
MySQL-clientr-5.5.10-1.linux2.6.i386.rpm  
MySQL-devel-5.5.10-1.linux2.6.i386.rpm  
MySQL-embedded-5.5.10-1.linux2.6.i386.rpm  
MySQL-server-5.5.10-1.linux2.6.i386.rpm  
MySQL-shared-5.5.10-1.linux2.6.i386.rpm  
MySQL-test-5.5.10-1.linux2.6.i386.rpm  
使用 rpm命令安装 ,提示  
下載rpm  
\[root@my-desktop]#sudo apt-get install rpm  
正在读取软件包列表... 完成  
正在分析软件包的依赖关系树        
正在读取状态信息... 完成  
下列【新】软件包将被安装：  
正在分析软件包的依赖关系树        
  rpm  
升级了 0 个软件包，新安装了 1 个软件包，要卸载 0 个软件包，有 390 个软件包未被升级。  
\[root@my-desktop]#rpm -i MySQL-server-5.5.10-1.linux2.6.i386.rpm  
rpm: please use alien to install rpm packages on Debian, if you are really sure use --force-debian switch. See README.Debian for more details.  
下載alien  
sudo apt-get install alien  
正在读取软件包列表... 完成  
正在分析软件包的依赖关系树        
正在读取状态信息... 完成  
下列【新】软件包将被安装：  
正在分析软件包的依赖关系树        
  alien  
升级了 0 个软件包，新安装了 1 个软件包，要卸载 0 个软件包，有 390 个软件包未被升级。  
将rpm转换 为deb文件  
sudo alien MySQL-server-5.5.10-1.linux2.6.i386.rpm  
error: incorrect format: unknown tag  
Warning: Skipping conversion of scripts in package MySQL-server: postinst preinst prerm  
Warning: Use the --scripts parameter to include the scripts.

完成 后 会 出现 同名的 mysql-server\_5.5.10-2\_i386.deb文件  
dpkg -i mysql-server\_5.5.10-2\_i386.deb  
(正在读取数据库 ... 系统当前总共安装有 127642 个文件和目录。)  
正预备替换 mysql-server 5.5.10-2 (使用 mysql-server\_5.5.10-2\_i386.deb) ...  
正在解压缩将用于更替的包文件 mysql-server ...  
正在设置 mysql-server (5.5.10-2) ...

正在处理用于 install-info 的触发器...  
正在处理用于 man-db 的触发器...  
正在处理用于 ureadahead 的触发器...  
正在处理用于 libc-bin 的触发器...  
ldconfig deferred processing now taking place  
安装完成  
sudo cp /usr/share/mysql/my-small.cnf my.cnf

启动mysql  
root@vieri-desktop:/var/lib/mysql# /usr/sbin/mysqld -u root  
/usr/sbin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory  
需要下载libaio1  
root@vieri-desktop:/var/lib/mysql# sudo apt-get install libaio1  
正在读取软件包列表... 完成  
正在分析软件包的依赖关系树        
正在读取状态信息... 完成        
下列【新】软件包将被安装：  
  libaio1  
升级了 0 个软件包，新安装了 1 个软件包，要卸载 0 个软件包，有 390 个软件包未被升级。  
需要下载 9,512B 的软件包。  
解压缩后会消耗掉 77.8kB 的额外空间。  
获取：1 http://hk.archive.ubuntu.com/ubuntu/ lucid/main libaio1 0.3.107-3ubuntu2 \[9,512B]  
下载 9,512B，耗时 2秒 (3,907B/s)   
选中了曾被取消选择的软件包 libaio1。  
(正在读取数据库 ... 系统当前总共安装有 127634 个文件和目录。)  
正在解压缩 libaio1 (从 .../libaio1\_0.3.107-3ubuntu2\_i386.deb) ...  
正在设置 libaio1 (0.3.107-3ubuntu2) ...

正在处理用于 libc-bin 的触发器...  
ldconfig deferred processing now taking place  
完成

root@vieri-desktop:/var/lib/mysql# /usr/sbin/mysqld -u root  
110330 17:15:53 \[Note] Plugin 'FEDERATED' is disabled.  
/usr/sbin/mysqld: Table 'mysql.plugin' doesn't exist  
110330 17:15:53 \[ERROR] Can't open the mysql.plugin table. Please run mysql\_upgrade to create it.  
110330 17:15:53 InnoDB: The InnoDB memory heap is disabled  
110330 17:15:53 InnoDB: Mutexes and rw\_locks use InnoDB's own implementation  
110330 17:15:53 InnoDB: Compressed tables use zlib 1.2.3  
110330 17:15:53 InnoDB: Using Linux native AIO  
110330 17:15:53 InnoDB: Initializing buffer pool, size = 128.0M  
110330 17:15:54 InnoDB: Completed initialization of buffer pool  
InnoDB: The first specified data file ./ibdata1 did not exist:  
InnoDB: a new database to be created!  
110330 17:15:54  InnoDB: Setting file ./ibdata1 size to 10 MB  
InnoDB: Database physically writes the file full: wait...  
110330 17:15:54  InnoDB: Log file ./ib\_logfile0 did not exist: new to be created  
InnoDB: Setting log file ./ib\_logfile0 size to 5 MB  
InnoDB: Database physically writes the file full: wait...  
110330 17:15:54  InnoDB: Log file ./ib\_logfile1 did not exist: new to be created  
InnoDB: Setting log file ./ib\_logfile1 size to 5 MB  
InnoDB: Database physically writes the file full: wait...  
InnoDB: Doublewrite buffer not found: creating new  
InnoDB: Doublewrite buffer created  
InnoDB: 127 rollback segment(s) active.  
InnoDB: Creating foreign key constraint system tables  
InnoDB: Foreign key constraint system tables created  
110330 17:15:54  InnoDB: Waiting for the background threads to start  
110330 17:15:55 InnoDB: 1.1.5 started; log sequence number 0  
110330 17:15:56 \[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist

提示是指系统表不存在 ,需要初始化数据库  
root@vieri-desktop:/var/lib/mysql# mysql\_install\_db  
Installing MySQL system tables...  
OK  
Filling help tables...  
OK

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/bin/mysqladmin -u root password 'new-password'  
/usr/bin/mysqladmin -u root -h vieri-desktop password 'new-password'

Alternatively you can run:  
/usr/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 ; /usr/bin/mysqld\_safe &

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

Please report any problems with the /usr/bin/mysqlbug script!  
完成

root@vieri-desktop:/usr/local/mysql# groupadd mysql  
root@vieri-desktop:/usr/local/mysql# useradd -g mysql mysql  
启动 mysqld -u mysql  
root@vieri-desktop:/usr/local/mysql# mysqld -u mysql  
110331 11:38:40 \[Note] Plugin 'FEDERATED' is disabled.  
110331 11:38:40 InnoDB: The InnoDB memory heap is disabled  
110331 11:38:40 InnoDB: Mutexes and rw\_locks use InnoDB's own implementation  
110331 11:38:40 InnoDB: Compressed tables use zlib 1.2.3  
110331 11:38:40 InnoDB: Using Linux native AIO  
110331 11:38:40 InnoDB: Initializing buffer pool, size = 128.0M  
110331 11:38:40 InnoDB: Completed initialization of buffer pool  
110331 11:38:40 InnoDB: highest supported file format is Barracuda.  
110331 11:38:40  InnoDB: Waiting for the background threads to start  
110331 11:38:41 InnoDB: 1.1.5 started; log sequence number 1595675  
110331 11:38:42 \[Note] Event Scheduler: Loaded 0 events  
110331 11:38:42 \[Note] mysqld: ready for connections.  
Version: '5.5.10'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server (GPL)

记得/etc/my.cnf的权限为mysql用戶,否则启动异常  
root@vieri-desktop:/usr/sbin# mysql -u mysql  
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

停止进程  
root@vieri-desktop:/home/vieri# ps aux | grep mysql  
vieri     2511  0.5  2.5  78216 26072 ?        S    15:35   0:33 gedit /home/vieri/temp/mysql安装  
root      8796  0.2  3.0 290356 31248 pts/2    Sl+  17:14   0:00 mysqld -u root  
root      8868  0.0  0.0   3320   816 pts/0    S+   17:16   0:00 grep --color=auto mysql  
root@vieri-desktop:/home/vieri# kill 8796  
root@vieri-desktop:/home/vieri# ps aux | grep mysql  
vieri     2511  0.5  2.5  79240 26112 ?        Sl   15:35   0:36 gedit /home/vieri/temp/mysql安装  
root      8897  0.0  0.0   3320   816 pts/0    S+   17:20   0:00 grep --color=auto mysql

利用腳本启动  
root@vieri-desktop:/var/lib/mysql# /etc/init.d/mysql start  
Starting MySQL *

利用程序启动守护线程  
root@vieri-desktop:/var/lib/mysql# mysqld\_safe -u mysql &  
\[1] 7595s  
root@vieri-desktop:/var/lib/mysql# 110407 16:28:49 mysqld\_safe Logging to '/var/lib/mysql/vieri-desktop.err'.  
110407 16:28:49 mysqld\_safe Starting mysqld daemon with databases from /var/lib/mysql  
110407 16:30:29 mysqld\_safe mysqld from pid file /var/lib/mysql/vieri-desktop.pid ended  
^C  
\[1]+  Done                    mysqld\_safe -u mysql

参考[http://www.gagahappy.com/ubuntu-mysql-add-to-service/](http://www.gagahappy.com/ubuntu-mysql-add-to-service/)设置开机启动

root@vieri-desktop:/home/vieri# cp usr/share/mysql/mysql.server /etc/init.d/mysql  
root@vieri-desktop:/home/vieri# chmod +x /etc/init.d/mysql  
chkconfig -add mysql命令报错  
用ubantu带的update-rc.d命令添加自启动  
root@vieri-desktop:/home/vieri# cd /etc/init.d  
root@vieri-desktop:/etc/init.d# update-rc.d mysql defauts  
update-rc.d: warning: mysql start runlevel arguments (none) do not match LSB Default-Start values (2 3 4 5)  
update-rc.d: warning: mysql stop runlevel arguments (none) do not match LSB Default-Stop values (0 1 6)  
usage: update-rc.d \[-n] \[-f] &lt;basename&gt; remove  
       update-rc.d \[-n] &lt;basename&gt; defaults \[NN | SS KK]  
       update-rc.d \[-n] &lt;basename&gt; start|stop NN runlvl \[runlvl] \[...] .  
       update-rc.d \[-n] &lt;basename&gt; disable|enable \[S|2|3|4|5]  
        -n: not really  
        -f: force  
添加  
root@vieri-desktop:/etc/init.d# update-rc.d mysql defaults  
 Adding system startup for /etc/init.d/mysql ...  
   /etc/rc0.d/K20mysql -&gt; ../init.d/mysql  
   /etc/rc1.d/K20mysql -&gt; ../init.d/mysql  
   /etc/rc6.d/K20mysql -&gt; ../init.d/mysql  
   /etc/rc2.d/S20mysql -&gt; ../init.d/mysql  
   /etc/rc3.d/S20mysql -&gt; ../init.d/mysql  
   /etc/rc4.d/S20mysql -&gt; ../init.d/mysql  
   /etc/rc5.d/S20mysql -&gt; ../init.d/mysql

查看启动

root@vieri-desktop:/etc/init.d# chkconfig --list mysql  
mysql                     0:off  1:off  2:on   3:on   4:on   5:on   6:off

删除  
The disable|enable API is not stable and might change in the future.  
root@vieri-desktop:/etc/init.d# update-rc.d -f mysql remove  
 Removing any system startup links for /etc/init.d/mysql ...  
   /etc/rc0.d/K20mysql  
   /etc/rc1.d/K20mysql  
   /etc/rc2.d/S20mysql  
   /etc/rc3.d/S20mysql  
   /etc/rc4.d/S20mysql  
   /etc/rc5.d/S20mysql  
   /etc/rc6.d/K20mysql