源码构建MySQL服务器

MySQL安装与使用教程
本文介绍了MySQL数据库的两种安装方式:Yum安装和源码安装,并详细解释了如何配置MySQL作为系统服务,包括创建数据库、表及用户权限管理等基本操作。

      MySQL是一个开放源码的小型关联式数据库管理系统,由于其体积小,速度快,总体拥有成本低,被广泛的做的网站数据库,目前主流的网站架构为LAMP(linux + apache + mysql + php)和 LNMP( linux + nginx + mysql + php )

        MySQL 有两在引擎:MyISAM  

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

                                         innoDB

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


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

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


        源码安装:

            cd /usr/src

            wget http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.63.tar.gz

            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

            注意:如果出现wKioL1XGLCywQaytAABQJUjqQ7s631.jpg错误,请执行: yum -y install ncurses-devel    然后重新./configure



        配置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';       

本文转自   tianshuai369   51CTO博客,原文链接:     http://blog.51cto.com/songqinglong/1683021


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值