参考:http://www.51testing.com/?uid-113838-action-spacelist-type-blog-itemtypeid-16873
1.下载数据库
MySQL-client-xxx.rpm MySQL-server-xxx.rpm
2.安装mysql server
[root@localhost mytools]# rpm -qa|grep MySQL 检查是否已经安装了mysql这里有可能是mysql
卸载:[root@localhost mytools]# rpm -e --nodeps MySQL-XXX
[root@localhost mytools]# rpm -ivh MySQL-server-5.5.8-1.linux2.6.i386.rpm
Preparing... ########################################### [100%]
1:MySQL-server ########################################### [100%]
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 localhost.localdomain 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.
Please report any problems with the /usr/bin/mysqlbug script!
(说明:
1. 出现以上信息,表明已经安装成功,需要到/usr/bin下设置root账号
2. RPM(RedHat Package Manager)语法解析:
2.1 RPM 是以一种数据库记录的方式来将你所需要的套件安装到你的 Linux 主机的一套管理程序
2.2语法:rpm 参数 待安装程序.rpm
2.3主要安装以rpm结尾的安装包,还有*.src.rpm结尾的,需要先SRPM(Source Code)编译成RPM,然后再安装
2.4 RPM安装的程序都会被安装到预设目录中:
/etc |
一些设定文件放置的目录,例如 /etc/crontab |
/usr/bin |
一些可执行档案 |
/usr/lib |
一些程序使用的动态函式库 |
/usr/share/doc |
一些基本的软件使用手册与说明文件 |
/usr/share/man |
一些 man page 档案 |
)
3. 设定mysql密码
[root@localhost mytools]# /usr/bin/mysqladmin -u root password “manager”
bash: /usr/bin/mysqladmin: No such file or directory
(说明:系统提示找不到mysqladmin这个文件或目录,怎么办呢?开始排错吧:
1. 首先就是到/usr/bin目录下面查看所有以mysql开头的内容(ll mysql*),共发现14个文件或目录(mysqlbug、mysql_convert_table_format、mysqld_multi、mysqld_safe、mysqldumpslow、mysql_fix_extensions、mysqlhotcopy、mysql_install_db、mysql_secure_installation、mysql_setpermission、mysqltest、mysql_tzinfo_to_sql、mysql_upgrade、mysql_zap)确实没有mysqladmin,那又是什么原因呢?
2. 再去查看一下mysql server安装完成后各目录中的文件变化吧
2.1数据库目录 /var/lib/mysql/
2.2配置文件目录 /usr/share/mysql(mysql.server命令及配置文件)
2.3相关命令所在目录 /usr/bin
2.4 启动脚本/etc/init.d(启动脚本文件mysql的目录)
3. 网上资料说只有安装了mysql-client端才会出现mysqladmin
mysqladmin is part of the mysql-client package, so you have to install that package in order to use mysqladmin, mysql etc
)
3.安装mysql client
[root@localhost mytools]# rpm -ivh MySQL-client-5.5.8-1.linux2.6.i386.rpm
Preparing... ########################################### [100%]
1:MySQL-client ########################################### [100%]
(说明:安装完成后查看(ll /usr/bin/mysql*),/usr/bin/目录下多了很多文件,由安装完server后的14个,变成了26个,并且有了mysqladmin文件
mysql
mysqlaccess
mysqlaccess.conf
mysqladmin
mysqlbinlog
mysqlbug
mysqlcheck
mysql_convert_table_format
mysqld_multi
mysqld_safe
mysqldump
mysqldumpslow
mysql_find_rows
mysql_fix_extensions
mysqlhotcopy
mysqlimport
mysql_install_db
mysql_secure_installation
mysql_setpermission
mysqlshow
mysqlslap
mysqltest
mysql_tzinfo_to_sql
mysql_upgrade
mysql_waitpid
mysql_zap
)
4.设置mysql的root管理员账号密码
[root@localhost bin]# mysqladmin -u root password manager
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!
(说明:安装完client后直接执行不行,告诉我们不能连接到MySQL server,要求检查mysqld是否在运行并且socket文件'/var/lib/mysql/mysql.sock'是否存在
1. 查看mysql默认端口号3306是否被占用
1.1 netstat –an 命令查看mysql默认端口3306的情况,没有查找到
[root@localhost bin]# netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:878 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
Active UNIX domain sockets (servers and established)
1.2 用netstat -pan|grep 3306查看短款的情况也可以
[root@localhost bin]# netstat -pan|grep 3306 #查询结果为空
[root@localhost bin]#
2. 紧接着进入/var/lib/mysql下面查看”mysql.sock”文件是否存在,不存在
3. [root@localhost /]# /etc/rc.d/init.d/mysql status
MySQL is not running [FAILED]
通过上面的几种检查结果可以初步断定mysql服务还没有启动,那先启动mysql服务吧
)
1.启动mysql服务
启动mysql的方式有很多
1. MySQL安装完成后启动文件mysql在/etc/init.d目录下,在需要启动时运行下面命令即可。
[root@localhost]# /etc/init.d/mysql start
2. 停止服务
[root@localhost]# /usr/bin/mysqladmin -u root -p shutdown
3. 开机自启动
一般情况下mysql安装完成后会被注册为系统服务,可以通过/sbin/chkconfig –list命令检查mysql是否被注册为系统服务
[root@localhost /]# /sbin/chkconfig --list
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
如果已经注册则执行 service mysql start 启动服务,停止则service mysql stop
[root@localhost sbin]# service mysql start
Starting MySQL. [ OK ]
如果没有注册则执行将mysql加入到系统的启动服务组里面去
[root@localhost sbin]# /sbin/chkconfig -- add mysql
把MySQL从启动服务组里面删除
[root@localhost sbin]# /sbin/chkconfig --del mysql
4. 继续上面的操作,修改mysql的root用户的密码
[root@localhost bin]# mysqladmin -uroot password "manager"
此处可能回报错误
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!
解决办法:# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
# bin/mysql -u root
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1
Server version: 5.0.45 MySQL Community Server (GPL)
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
接下来执行 # mysql -u root mysql
mysql>
这里要重新在设置一遍密码
UPDATE user SET Password=PASSWORD('newpassword');
5.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)