linux下安装mysql

(1)先安装cmake(mysql5.5以后是通过cmake来编译的)

[root@ rhel5 local]#tar -zxv -f cmake-2.8.4.tar.gz
[root@ rhel5 local]#cd cmake-2.8.4
[root@ rhel5 cmake-2.8.4]#./configure
[root@ rhel5 cmake-2.8.4]#make
[root@ rhel5 cmake-2.8.4]#make install
(2)安装mysql
[root@ rhel5 local]#tar -zxv -f mysql-5.5.10.tar.gz
    
[root@ rhel5 local] # cd mysql-5.5.10 [root@ rhel5 mysql-5.5.10] # cmake . [root@ rhel5 mysql-5.5.10] # make [root@ rhel5 mysql-5.5.10] # make install

(3)创建系统数据库的表
[root@ rhel5 mysql]# cd /usr/local/mysql
[root@ rhel5 mysql]# scripts/mysql_install_db --user=mysql

(6)将mysql添加到服务

 

[root@ rhel5 mysql]# cp support-files/mysql.server /etc/init.d/mysql //将mysql的启动服务添加到系统服务中

(4)设置环境变量

[root@ rhel5~]# vi /root/.bash_profile

在PATH=$PATH:$HOME/bin添加参数为:

PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib

[root@ rhel5~]#source /root/.bash_profile

(5)手动启动mysql

[root@ rhel5~]# cd /usr/local/mysql

[root@ rhel5 mysql]# ./bin/mysqld_safe --user=mysql &   //启动MySQL,但不能停止

启动日志写在此文件下:/usr/local/mysql/data/localhost.err

关闭MySQL服务

[root@ rhel5 mysql]# mysqladmin -u root -p shutdown  //这里MySQL的root用户还没有配置密码,所以为空值。需要输入密码时,直接点回车键即可。
 
  
(7)修改MySQL的root用户的密码以及打开远程连接

   
[root@ rhel5~] # mysql -u root mysql mysql>use mysql; mysql>desc user; mysql> GRANT ALL PRIVILEGES ON *.* TO root@ " % " IDENTIFIED BY " root ";  //为root添加远程连接的能力。 mysql>update user set Password = password('xxxxxx') where User='root'; mysql>select Host,User,Password from user where User='root'; mysql>flush privileges; mysql>exit 重新登录:mysql -u root -p 若还不能进行远程连接,则关闭防火墙 [root@ rhel5~] # /etc/rc.d/init.d/iptables stop
 
 

你可能感兴趣的:(linux)