TOM's profileTOM WANGPhotosBlogLists Tools Help

Blog


    MySQL on Linux & BSD

    [关于]
    Linux 下有许多的数据服务器,其中 MySQL 是一个小型关系型数据库管理系统,开发者为瑞典MySQL AB公司,在2008年1月16号被Sun公司收购。目前 MySQL 被广泛地应用在因特网上的中小型网站中。由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为了降低网站总体拥有成本而选择了 MySQL 作为网站数据库,更重的一点是 MySQL 有免费的版本提供。
    [详细的安装方法]
    这一章节主要描述最常用的MYSQL,我们可以从 MYSQL 的官方网站下载到最新的 MYSQL 源代码版本。把下载来的包解压缩,用以下的命令。

    tar -zxvf mysql-5.1.30.tar.gz

    添加 MYSQL 用户及组。

    groupadd mysql
    useradd mysql -g mysql

    进行解开的包目录进行编译并安装。

    cd mysql-5.1.30
    ./configure --prefix=/usr/local/mysql
    make
    make install clean

    如果没有提示任何错误的话,那就代表已经安装就成功了,不过不是安装成功了就可以运行得了的,还要进行下面一些非常关键的设置,先创建并设置 MYSQL 的数据库存放目录与主目录的权限。

    chown -R mysql:mysql /usr/local/mysql
    mkdir -p /home/database/mysql
    chown -R mysql:mysql /home/database/mysql

    然后再把 MYSQL 的配置文件复制一份到系统目录下,并对其进行编辑,添加一行 datadir = /home/database/mysql 就行了。

    cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
    vi /etc/my.cnf

    再执行对 MYSQL 数据库的初始设置。

    /usr/local/mysql/bin/mysql_install_db --user=mysql

    如果没有出现什么错误的话,那现在的 MYSQL 已经可以正常运行了,只要执行如下的命令即可。

    /usr/local/mysql/bin/mysqld_safe --user=mysql

    如果没有出现错误的话,MYSQL 就已经正常运行了,如果有错误的话,会在 /home/database/mysql 目录下产生一个以 .err结 尾的文件,可以通过查看些文件内容的方法来寻求错误点,然后进行排错,通常都是因为会权限问题才会导致 MYSQL 失败,所以请仔细核对以上的步骤。

    [附:随系统自动运行的方法]
    如果你的系统是 Redhat 家庭的话,通常我们会把 MYSQL 加入到服务里面,按下面的操作即可。

    cp /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysql
    chmod +x /etc/rc.d/init.d/mysql
    chkconfig --add /etc/rc.d/init.d/mysql
    chkconfig --level 345 mysql on

    如果你是 BSD 家族的话,你需要把 MYSQL 加入到 /etc/rc.conf。

    cp /usr/local/mysql/share/mysql/mysql.server /usr/local/etc/rc.d/mysql
    cp /etc/my.cnf /usr/local/etc/my.cnf
    chmod +x /usr/local/etc/rc.d/mysql
    echo 'mysql_datadir="/home/databse/mysql"' >> /etc/rc.conf
    echo 'mysql_enable="YES"' >> /etc/rc.conf


    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://cidsmake.spaces.live.com/blog/cns!F4B098FAB5A98F61!631.trak
    Weblogs that reference this entry
    • None