mysql5.5.28在Linux下的安装

Posted 雨花梦

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql5.5.28在Linux下的安装相关的知识,希望对你有一定的参考价值。

http://dev.mysql.com/downloads/mysql/ 官网上下载mysql-5.5.28-linux2.6-i686.tar.gz.

2.       解压

   假如tar包在/home/zdw/software目录下

#tar -xvf mysql-5.5.28-linux2.6-i686.tar.gz

3.       移动到/usr/local/mysql

#mv mysql-5.5.28-linux2.6-i686 /usr/local/

添加快捷方式mysql指向mysql-5.5.28-linux2.6-i686

#ln -s mysql-5.5.28-linux2.6-i686/ mysql

4.       安装依赖的lib包:执行/usr/local/mysql/bin/mysqld,报错

/usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot               open shared object file: No such file or directory

使用apt-cache search libaio,找到如下软件源

libaio-dev - Linux kernel AIO access library - development files

libaio1 - Linux kernel AIO access library - shared library

libaio1-dbg - Linux kernel AIO access library - debugging symbols

使用#apt-get install libaio1 安装

5.       配置用户,目录

#groupadd mysql

#useradd -r -g mysql mysql

#cd /usr/local/mysql

#chown -R mysql .

#chgrp -R mysql .

6.       初始化mysql

    假如当前目录为/usr/local/mysql

#scripts/mysql_install_db --user=mysql

7.       启动mysql

最简单的启动方式:

#/usr/local/mysql/bin/mysqld --user=mysql

默认情况下使用/usr/local/mysql/data作为mysql的数据目录,包括数据库文件,log日志。

常用的mysql启动参数:

/usr/local/mysql/bin/mysqld  --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data  --port=3306 --socket=/tmp/mysql.socks

推荐的启动mysql

#/usr/local/mysql/support-files/mysql.server start

启动完成之后用ps -ef |grep mysql 命令查看是否启动

8.       登录mysql

#/usr/local/mysql/bin/mysql -u root -p

默认密码为空

 

修改root密码

mysql>use mysql ;
mysql>update user set password=PASSWORD("123456") where user=‘root‘;
mysql>FLUSH PRIVILEGES;

9.       关闭mysql

最简单的方式

#killall mysqld

推荐的方式

#/usr/local/mysql/support-files/mysql.server stop

使用mysql.server stop关闭mysqld会销毁pid文件,并做容错操作,但是最后也是调用kill命令kill mysql。

 

关闭mysql,尽量不要用kill -9 mysql_pid或者是killall -9 mysql,否则mysql进程无法做退出处理,就可能会丢失数据,甚至导致表损坏。

 

10.   浅析mysql.server脚本的启动流程

mysql.server脚本可以看到在以下脚本调用mysqld_safe这个bash

$bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &

默认情况下,$bindir/mysqld_safe就是/usr/local/mysql/bin/mysqld_safe这个shell,我的本机的调用参数如下:

/bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/blue-pc.pid

而mysqld_safe也是一个shell,可以看到在这个脚本在初始化N多变量后,调用

eval_log_error "$cmd"

这个shell function最后就是调用

 #echo "Running mysqld: [$cmd]" eval "$cmd"

在我本机,这个$cmd就是

/usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/blue-pc.err --pid-file=/usr/local/mysql/data/blue-pc.pid

参考文章:
http://dev.mysql.com/doc/refman/5.5/en/binary-installation.html
本文在Ubuntu11.04和Fedora14下测试成功。

 

[email protected]:/usr/local/mysql-5.5.28-linux2.6-i686# scripts/mysql_install_db --user=mysql
scripts/mysql_install_db: 1: scripts/mysql_install_db: ./bin/my_print_defaults: not found
Neither host ‘zwj-virtual-machine1‘ nor ‘localhost‘ could be looked up with
./bin/resolveip
Please configure the ‘hostname‘ command to return a correct
hostname.
If you want to solve this at a later stage, restart this script
with the --force option
[email protected]:/usr/local/mysql-5.5.28-linux2.6-i686# scripts/mysql_install_db --user=mysql --force option
scripts/mysql_install_db: 1: scripts/mysql_install_db: ./bin/my_print_defaults: not found
Installing MySQL system tables...
scripts/mysql_install_db: 403: scripts/mysql_install_db: ./bin/mysqld: not found

Installation of system tables failed! Examine the logs in
./data for more information.

You can try to start the mysqld daemon with:

shell> ./bin/mysqld --skip-grant &

and use the command line tool ./bin/mysql
to connect to the mysql database and look at the grant tables:

shell> ./bin/mysql -u root mysql
mysql> show tables

Try ‘mysqld --help‘ if you have problems with paths. Using --log
gives you a log in ./data that may be helpful.

Please consult the MySQL manual section
‘Problems running mysql_install_db‘, and the manual section that
describes problems on your OS. Another information source are the
MySQL email archives available at http://lists.mysql.com/.

Please check all of the above before mailing us! And remember, if
you do mail us, you MUST use the ./bin/mysqlbug script!

[email protected]:/usr/local/mysql-5.5.28-linux2.6-i686#

以上是关于mysql5.5.28在Linux下的安装的主要内容,如果未能解决你的问题,请参考以下文章

如何在lnmp上部署Thinkphp

wamp经典安装

Testlink在Linux下的安装方法

linux下的软件默认安装目录在哪?

linux下的iso镜像怎么安装

如何安装linux系统下的ffmpeg