天天看点

源码构建MySQL服务器

        MySQL 有两在引擎:MyISAM  

                                          特点:强调性能,比 innoDB 快,但不提供事务支持,适合执行大量 SELECT(查询)操作。

                                         innoDB

                                          特点: 提供事务支持事务,外部键等高级数据库功能,适合执行大量的INSERT 或                                                                 UPDATE, 支持行锁。

        MySQL  安装方式有两种:Yum / rpm 和 tar 源码安装。

        yum 安装比较简单:yum -y install mysql-server  mysql-devel  mysql

        源码安装:

            cd /usr/src

            tar xzf mysql-5.1.63.tar.gz

            cd mysql-5.1.63

            /configure --prefix=/usr/local/mysql    --enable-assembler  --with-unix-socket-path=/tmp/mysql.sock --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static  --with-extra-charsets=gbk,gb2312,utf8 --enable-thread-safe-client --with-big-tables --enable-local-infile --with-ssl

            &&make -j8&&make -j8 install

        配置Mysql 服务为系统服务:

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

            cp /usr/local/mysql/share/mysql/mysql.server          /etc/rc.d/init.d/mysqld

            chkconfig  --add  mysqld

            chkconfig  --level 35  mysqld on

            /etc/init.d/mysqld  restart

            cd  /usr/local/mysql

            useradd  mysql

            chown  -R  mysql.mysql   /usr/local/mysql

            /usr/local/mysql/bin/mysql_install_db  --user=mysql   --datadir=./var  --basedir=/usr/local/mysql

            chown  -R  mysql.mysql   var

            /etc/init.d/mysqld    restart

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

            新建数据库,给数据库授权:

            /usr/local/mysql/bin/mysql                    #登陆mysql

            >create database test_db;                        #新建库

            >use test_db;                                            #进入库

            >create table test_db(id varchar(20),name varchar(20));                    #新建表

            >grant  all  on  text_db.*  to   test@localhost  identified  by  '123>456';        #赋予本地完全权限 

            > flush privileges;                        #刷新权限

            #删除

            >drop database test_db;                                                            #删除库

            >drop table test01;                                                                    #删除表

            >delete  from  test01;                                                                #清空表内容

            >show  variables like '%char%';                                                #查看数据库字符集

            >test_db > /data/back/test_db.sql                                                      #mysql 导出(备份)

            #mysql  -uroot -p123456  test_db  <  /data/back/test_db.sql            #mysql  导入

            #mysqladmin  -uroot -p123456  newpasswd   newpasswd                #修改mysql  root密码

            #修改mysql 字符集为UTF-8 的方法

            [client]    字段里加入:       default-character-set=utf8

            [mysqld]    字段里加入:     character-set-server=utf8

            [mysql]    字段里加入:       default-character-set=utf8

            破解mysql 的密码:

                /usr/bin/mysqld_safe  --user=mysql  --skip-grant-tables  &

                #mysql

                >use  数据库名称

                >update  user  set  password=password('00000') where user='root';            

本文转自 菜鸟的征程 51CTO博客,原文链接:http://blog.51cto.com/songqinglong/1683021