Mysql下载地址:http://www.mysql.com/downloads/mysql/ 

1.下载mysql源码并解压
  1. [root@server3 ~]# tar zxf mysql-5.1.58.tar.gz   
  2. [root@server3 ~]# cd mysql-5.1.58 
 
2.配置选项

  1. [root@server3 mysql-5.1.58]# ./configure --prefix=/usr/local/mysql5.1.58 \  
  2. --localstatedir=/usr/local/mysql5.1.58/data \  
  3. --without-debug \  
  4. --without-ndb-debug \  
  5. --with-collation=utf8_general_ci \  
  6. --enable-thread-safe-client \  
  7. --enable-assembler \  
  8. --enable-profiling \  
  9. --with-big-tables \  
  10. --with-mysqld-ldflags=-all-static \  
  11. --with-client-ldflags=-all-static \  
  12. --with-charset=utf8 \  
  13. --with-extra-charsets=all \  
  14. --with-plugins=innobase,partition \  
  15. --with-mysqld-user=mysql \  
  16. --without-embedded-server \  
  17. --with-unix-socket-path=/tmp/mysql.sock  
3.编译安装

  1. [root@server3 mysql-5.1.58]#make && make install 
4.增加mysql 用户

  1. [root@server3 mysql-5.1.58]#useradd mysql 
5.建立数据目录
 
  1. [root@server3 mysql-5.1.58]#mkdir /usr/local/mysql5.1.58/data 
6.复制配置文件到mysql安装目录

  1. [root@server3 mysql-5.1.58]# cp support-files/my-medium.cnf /usr/local/mysql5.1.58/my.cnf 
7.改变mysql安装目录的属主和属组为mysql和root

  1. [root@server3 mysql-5.1.58]#chown -R root:mysql /usr/local/mysql5.1.58 
8.把mysql数据目录的属主和属组修改为mysql和mysql,使mysql用户可以写入

  1. [root@server3 mysql-5.1.58]#chown -R mysql:mysql/usr/local/mysql5.1.58/data 
9.以mysql用户身份初始化数据库

  1. [root@server3 mysql-5.1.58]#/usr/local/mysql5.1.58/bin/mysql_install_db --basedir=/usr/local/mysql5.1.58 --user=mysql 
10.启动Mysql服务
 
  1. [root@server3 ~]# /usr/local/mysql5.1.58/bin/mysqld_safe --defaults-file=/usr/local/mysql5.1.58/my.cnf --user=mysql & 
要开机启动服务把这条命令放到/etc/rc.local中

11.配置PATH路径
编辑vim /etc/profile,把mysql的bin目录加入到PATH路径里面

  1. export PATH=/usr/local/mysql5.1.58/bin:$PATH  
  2. [root@server3 ~]#source /etc/profile 
12.登录到mysql,由于没有mysql的root用户没有设置密码,所以直接输入mysql就可以登录

  1. [root@server3 ~]# mysql  
  2. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  3. Your MySQL connection id is 1  
  4. Server version: 5.1.58-log Source distribution  
  5.  
  6. Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.  
  7. This software comes with ABSOLUTELY NO WARRANTY. This is free software,  
  8. and you are welcome to modify and redistribute it under the GPL v2 license  
  9.  
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  11.  
  12. mysql> exit  
13.修改mysql的root用户密码

  1. [root@server3 ~]# mysqladmin -u root password '123456' 
14.再次登录到mysql
 
  1. [root@server3 ~]# mysql -uroot -p  
  2. Enter password:                         //这里输入root用户的密码  
  3.  Welcome to the MySQL monitor.  Commands end with ; or \g.  
  4. Your MySQL connection id is 5  
  5. Server version: 5.1.58-log Source distribution  
  6.  
  7. Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.  
  8. This software comes with ABSOLUTELY NO WARRANTY. This is free software,  
  9. and you are welcome to modify and redistribute it under the GPL v2 license  
  10.  
  11. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  12.  
  13. mysql> show databases;  
  14. +--------------------+  
  15. | Database           |  
  16. +--------------------+  
  17. | information_schema |  
  18. | mysql              |  
  19. | test               |  
  20. +--------------------+  
  21. 3 rows in set (0.00 sec)  
  22.  
  23. mysql>   

15.关闭mysql服务
  1. [root@server3 ~]#mysqladmin -uroot -p shutdown  
  2. nter password:                  //输入mysql的root用户密码