日期:2014-05-16  浏览次数:20633 次

手动安装Generic linux 版的mysql
在官方文档上可以找到:
http://dev.mysql.com/doc/refman/5.5/en/unix-postinstallation.html

如果不想看英文,可以看下我写的精简版:

在linux上安装mysql的步骤:

1. 下载linux通用版本的mysql: mysql-5.5.11-linux2.6-i686.tar.gz
2. 在解压缩之前,先建一个系统用户与用户组:
        groupadd mysql
        useradd -r -g mysql mysql        ---  -r选项意思是:这个用户不能作为终端登录用户,只能其他用户登录后,su过去。
3. 用root用户解压缩安装文件到/usr/local/mysql-5.5.11-linux2.6-i686    ---因为/usr/local目录只有root用户有权限写
        tar xzf mysql-5.5.11-linux2.6-i686.tar.gz -C /usr/local
4. 建一个link文件,方便使用:
        ln -s mysql-5.5.11-linux2.6-i686 mysql

5. 修改owner,group为mysql
        cd mysql
        chown -R mysql .
        chgrp -R mysql .

6. 用mysql用户执行脚本 ./scripts/mysql_install_db
7. 执行后,查看data文件夹下是否多出来几个数据库的目录: test, mysql, performance_schema
8. 用root用户将mysql安装目录下的所有文件的owner都改为root,除了data文件夹:  ---这样mysql目录就不会被轻易删除后修改了
        chown -R root .
        chown -R mysql data
9. 将bin目录加入到mysql用户的path中
10. 用mysql用户启动mysql:
        mysqld_safe
11.验证是否启动成功:
        mysqladmin --version
12.验证是否可以关闭mysql进程
        mysqladmin -u root shutdown
13.修改mysql的root密码:
        shell> mysql -u root
        mysql> UPDATE mysql.user SET Password = PASSWORD('newpwd') WHERE User = 'root';
        mysql> FLUSH PRIVILEGES;

14.新建一个用户,用于远程访问:    --- localhost 和 % 都要建,如果没有localhost的话,用户就会被当作anonymous用户
        mysql> create user 'user1'@'localhost' identified by 'user1';
        mysql> grant all privileges on *.* to 'user1'@'localhost' with grant option;
        mysql> create user 'user1'@'%' identified by 'user1';
        mysql> grant all privileges on *.* to 'user1'@'%' with grant option;

15.To check the privileges for an account:
        mysql> show grants for 'user1'@'localhost';

16.默认iptables没有开放3306端口给远程访问,所以需要在防火墙上打开一下:
        iptables -I INPUT -p tcp --dport=3306 -j ACCEPT
        service iptables save
        service iptables restart