Linux源码安装mysql步骤

创建文件夹:
 mkdir  /usr/local/webserver
 安装必要依赖包
      yum -y install gcc gcc-c++ make ncurses-devel
安装cmake包:
    tar zxvf cmake-2.8.12.2.tar.gz
    cd cmake-2.8.12.2
    ./bootstrap --prefix="/usr/local/webserver/cmake"  
    make && make install
源码安装ncurses:
   
    tar zxvf ncurses-5.9.tar.gz
    cd ncurses-5.9
    ./configure --prefix="/usr/local/webserver/ncurses" 
    make && make install
安装mysql源码(参数根据自己的配置来填写):
tar zxvf mysql-5.6.17.tar.gz 
    cd  mysql-5.6.17
/usr/local/webserver/cmake/bin/cmake . \
        -DCMAKE_INSTALL_PREFIX="/usr/local/webserver/mysql" \
        -DMYSQL_DATADIR="/usr/local/webserver/mysql/data" \
        -DMYSQL_UNIX_ADDR="/usr/local/webserver/mysql/data/mysql.sock" \
        -DMYSQL_TCP_PORT="3306" \
        -DDEFAULT_CHARSET=utf8 \
        -DDEFAULT_COLLATION=utf8_general_ci \
        -DWITH_EXTRA_CHARSETS=all \
        -DENABLED_LOCAL_INFILE=1 \
        -DWITH_INNOBASE_STORAGE_ENGINE=1 
    make && make install
#mysql初始化(my.cnf可根据自己的配置进行修改)
my.cnf
[client]
port=3306
socket=/usr/local/webserver/mysql/data/mysql.sock
 
[mysqld]
port=3306
basedir=/usr/local/webserver/mysql
datadir=/usr/local/webserver/mysql/data
socket=/usr/local/webserver/mysql/data/mysql.sock
user=mysql
default-time-zone=system
character-set-server=utf8
default-storage-engine=InnoDB
#cp mysqlmysql-5.6.17/my.cnf /usr/local/webserver/mysql/
        cd /usr/local/webserver/mysql/ 
        chown -R mysql:mysql . 
        ./scripts/mysql_install_db \
            --basedir="/usr/local/webserver/mysql" \
            --datadir="/usr/local/webserver/mysql/data" \
            --user=mysql
        #目录权限
        cd  /usr/local/webserver/mysql/ 
        chown -R root . 
        chown -R mysql data
        #删除多余文件和目录
        cd  /usr/local/webserver/mysql/ 
rm -rf COPYING README INSTALL-BINARY docs man
        #设置开机自动启动mysql
cp  mysql-5.6.17/support-files/mysql.server /etc/init.d/mysqld
        chmod +x /etc/init.d/mysqld
        chkconfig --add mysqld
        chkconfig mysqld on
****
        #启动mysql
        service mysqld start
  启动报错:

  Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist

  解决方案:清理data数据目录中的全部数据,然后从新初始化mysql:/scripts/mysql_install_db

        #访问权限设置
        /usr/local/webserver/mysql/bin/mysqladmin -uroot password "12344"
        /usr/local/webserver/mysql/bin/mysql -uroot -p123456  
grant all privileges on *.* to 'root'@'%' identified by '123456';


        #执行mysql_secure_installation进行优化
        cd /usr/local/webserver/mysql/ 
./bin/mysql_secure_installation
注(按照自身的需要来选择):
输入密码进入选择
Change the root password? [Y/n]
Remove anonymous users? [Y/n]
Disallow root login remotely? [Y/n]
Remove test database and access to it? [Y/n]
Reload privilege tables now? [Y/n]

posted @ 2016-07-21 13:22  字节  阅读(335)  评论(0编辑  收藏  举报