(一)MySQL_编译安装

一、MySql安装前的准备工作

(1)通过ubuntu自带的apt-get install安装所需的各个安装辅助工具:

          sudo apt-get install g++

          sudo apt-get install bison

          sudo apt-get install build-essential

          sudo apt-get install cmakelibncurses5-dev

          sudo apt-get install chkconfig

(2)创建服务于MySQL的用户组

          sudo groupadd mysql                                                                //创建mysql用户组

          sudo useradd -r -g mysql mysql -s/bin/false                         //添加mysql用户,设置mysql权限

(3)创建mysql安装目录

           sudo mkdir -p /usr/local/mysql                                                //创建mysql安装目录

           sudo mkdir -p /usr/locl/mysql/data                                          //创建mysql的data存放目录

           sudo chown -R mysql:mysql /usr/local/mysql/data              //将data目录的own和grp权限更改为mysql用户


二、编译安装MySQL

                   Ps:这里是官网最新的MySQL Community Server源码,下载地址: http://dev.mysql.com/downloads/

(1)下载,解压MySQL源码

           (假设下载包mysql-5.6.4-m7.tar.gz 在~/Download目录下)

            tar -xzf mysql-5.6.4-m7.tar.gz                                                     //解压压缩包到当前目录,即~/Download下

            sudo mv -f ~/Download/mysql-5.6.4-m7                                 //将mysql安装包mysql-5.6.4-m7移动到/usr/local目录下 

(2)编译安装

             cd /usr/local/mysql-5.6.4-m7                                                    //进入mysql安装目录

             sudo cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/usr/local/mysql/data                                                                                       //以上是利用cmake生成makefile文件,红色标记根据上述创建目录的具体路径而定

              sudo make                                                                                   //编译mysql

              sudo make install                                                                       //安装mysql

(3)配置MySQL

               sudo ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql           //设置mysql命令

               Ps:不同版本的MySQL的默认配置文件名称有差异,找不到my-default 就找my-medium即可。

               sudo cp ./support-files/my-default.cnf /etc/my.cnf                  //复制默认配置文件设置为全局

               sudo cp ./support-files/mysql.server /etc/init.d/mysqld         //设置MySQL开机自启动

               sudo chmod +x /etc/init.d/mysqld

               sudo chkconfig mysqld on                                                           //生效设置

               //以下进行初始化

               sudo /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

(4)其他设置

                sudo /usr/local/mysql/bin/mysqladmin -u root password NewPasswords          //密码设置,NewPasswords是新密码

                export PATH=$PATH:/usr/local/mysql/bin                                 //添加环境变量,直接通过mysql命令进入数据库

                安装完成。


三、可能会遇到的问题

               A. cmake的时候报错

                  原因:可能缺少ncurses-devel包

                  解决方案:yum install ncurses-devel                                  //利用yum安装ncurses-devel包

                                      rm CMakeCache.txt                                              //删除Cmake遗留文件CMakeCache.txt

                                      cmake                                                                     //重新执行cmake即可

               B. 用service命令启动MySQL服务时,可能会报错:/sbin/insserv: No such file or directory

                   原因:Ubuntu 自身问题

                   解决方案:sudo ln -s /usr/lib/insserv/insserv /sbin/insserv

         C. 启动MySQL的时候提示找不到mysql.sock ,Can't connect to local MySQL server through socket '/tmp/mysql.sock'

                    mysql.sock文件在服务器正常启动之后将会在/usr/local/mysql目录下自动生成

                 (a) 原因:MySQL进程僵死

                                        sudo ps -A|grep mysql                                       //查看mysql相关进程

                            解决方案:

                                         kill -9 [mysql僵死进程号]                                    //杀死mysql僵死进程

                                         sudo service mysql.server status                    //确认mysql运行状态

                                         sudo service mysql.server start                        //启动mysql

                 (b)原因:权限问题

                            解决方案:

                                          sudo chown -R mysql:mysql /usr/local/mysql           //修改mysql权限

                                          sudo service mysql.server start                        //启动MySql服务器

                  (c)原因:配置文件my.cnf问题

                            解决方案:

                                          系统中找到mysql.sock文件

                                          根据 /etc/my.cnf 配置文件中[mysqld] 部分里socket 路径

                                          创建软链接将该mysql.sock 链接到socket路径所在目录下即可;

                                          比方说将 /tmp/mysql.sock link 到 /var/lib/mysql 目录里即可:

                                          sudo ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock    //此处路径因具体情况而定


                                         

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值