---
title: "liunx 安装mysql "
author: "smallsilver"
date: "2011-04-23T15:35:59Z"
tags: []
categories: ["数据库"]
slug: "liunx-mysql"
draft: false
lastmod: "2011-04-23T15:35:59Z"
id: 1013498
url: "https://wangde.iteye.com/blog/1013498"
---

先用下面命令查看你的机器上是否有别的版本的mysql  
rpm -qa|grep mysql  
mysql-3.23.49-3  
用下面命令卸载掉，并把/var/lib/mysql/ 下的文件删除。  
\[root@wangde mysql]#rpm -e  mysql-3.23.49-3  
\[root@wangde mysql]#rm -rf /var/lib/mysql

\[root@wangde mysql]# ls  
MySQL-client-5.5.11-1.linux2.6.i386.rpm  
MySQL-server-5.5.11-1.linux2.6.i386.rpm  
MySQL-shared-5.5.11-1.linux2.6.i386.rpm  
\[root@wangde mysql]# rpm -ivh MySQL-shared-5.5.11-1.linux2.6.i386.rpm  
警告：MySQL-shared-5.5.11-1.linux2.6.i386.rpm: V3 DSA 簽章：NOKEY, key ID 5072e1 f5  
準備中...                ########################################### \[100%]  
   1:MySQL-shared           ########################################### \[100%]  
\[root@wangde mysql]#  
\[root@wangde mysql]# rpm -ivh MySQL-server-5.5.11-1.linux2.6.i386.rpm  
警告：MySQL-server-5.5.11-1.linux2.6.i386.rpm: V3 DSA 簽章：NOKEY, key ID 5072e1 f5  
準備中...                ########################################### \[100%]  
        已經安裝 MySQL-server-5.5.11-1.linux2.6 套件  
\[root@wangde mysql]# rpm -e MySQL-server-5.5.11-1.linux2.6  
\[root@wangde mysql]# rpm -ivh MySQL-server-5.5.11-1.linux2.6.i386.rpm  
警告：MySQL-server-5.5.11-1.linux2.6.i386.rpm: V3 DSA 簽章：NOKEY, key ID 5072e1 f5  
準備中...                ########################################### \[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 wangde 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!

 

Notes regarding SELinux on this platform:  
\=========================================

The default policy might cause server startup to fail because it is  
not allowed to access critical files.  In this case, please update  
your installation.

The default policy might also cause inavailability of SSL related  
features because the server is not allowed to access /dev/random  
and /dev/urandom. If this is a problem, please do the following:

  1) install selinux-policy-targeted-sources from your OS vendor  
  2) add the following two lines to /etc/selinux/targeted/src/policy/domains/pro gram/mysqld.te:  
       allow mysqld\_t random\_device\_t:chr\_file read;  
       allow mysqld\_t urandom\_device\_t:chr\_file read;  
  3) cd to /etc/selinux/targeted/src/policy and issue the following command:  
       make load

\[root@wangde mysql]#  
\[root@wangde mysql]# ls  
MySQL-client-5.5.11-1.linux2.6.i386.rpm  
MySQL-server-5.5.11-1.linux2.6.i386.rpm  
MySQL-shared-5.5.11-1.linux2.6.i386.rpm  
\[root@wangde mysql]# rpm -ivh MySQL-client-5.5.11-1.linux2.6.i386.rpm  
警告：MySQL-client-5.5.11-1.linux2.6.i386.rpm: V3 DSA 簽章：NOKEY, key ID 5072e1 f5  
準備中...                ########################################### \[100%]  
   1:MySQL-client           ########################################### \[100%]  
\[root@wangde mysql]# mysqladmin -u root password root  
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' ex ists!  
\[root@wangde mysql]# service mysql start  
Starting MySQL...                                          \[  OK  ]  
\[root@wangde mysql]# mysqladmin -u root password root  
\[root@wangde mysql]# mysqladmin -u root -h wangde password root  
\[root@wangde mysql]# service mysql restart  
Shutdown MySQL...                                          \[  OK  ]  
Starting MySQL...                                          \[  OK  ]  
\[root@wangde mysql]#  
 下面就介绍一下这几个目录。

　　 1、数据库目录  
　　 /var/lib/mysql/

　　 2、配置文件  
　　 /usr/share/mysql（mysql.server命令及配置文件）

　　 3、相关命令  
　　 /usr/bin(mysqladmin mysqldump等命令)

　　 4、启动脚本  
　　 /etc/rc.d/init.d/（启动脚本文件mysql的目录）  
　 五、修改登录密码

　　 MySQL默认没有密码，安装完毕增加密码的重要性是不言而喻的。

　　 1、命令  
　　 usr/bin/mysqladmin -u root password 'new-password'  
　　 格式：mysqladmin -u用户名 -p旧密码 password 新密码

　　 2、例子  
　　 例1：给root加个密码123456。  
　　 键入以下命令 ：  
　　 \[root@wangde local]# /usr/bin/mysqladmin -u root password 123456  
　　 注：因为开始时root没有密码，所以-p旧密码一项就可以省略了。

　　 3、测试是否修改成功  
　　 1）不用密码登录  
　　 \[root@wangde local]# mysql  
　　 ERROR 1045: Access denied for user: ['root@localhost'](mailto:'root@localhost') (Using password: NO)  
　　 显示错误，说明密码已经修改。  
　　 2）用修改后的密码登录  
　　 \[root@wangde /]# mysql -u root -p  
Enter password:  
Welcome to the MySQL monitor.  Commands end with ; or \\g.  
Your MySQL connection id is 3  
Server version: 5.5.11 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its  
affiliates. Other names may be trademarks of their respective  
owners.

Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.

mysql&gt;