您的位置:首页 > 数据库 > MySQL

Mysql 编译安装

2017-04-04 15:57 281 查看
Mysql 编译安装

========================================

一:准备

1.1:源码下载

        mysql 官网:http://dev.mysql.com/downloads/mysql/

        github 地址:https://github.com/mysql/mysql-server

1.2:安装依赖

      ~]# yum -y install perl perl-devel autoconf cmake gcc gcc-c++ ncurses ncurses-devel

1.3:备注

    -DCMAKE_INSTALL_PREFIX= 安装主目录

    -DSYSCONFDIR= 配置文件安装位置

    -DMYSQL_DATADIR= 数据目录

二:编译安装

2.1:编译初始目录

  ~]# mkdir -pv /data/mysql/

  ~]# mkdir /etc/mysql/

  ~]# useradd -r mysql

  ~]# rm -rf  /etc/my.cnf

  ~]# rm -rf /etc/my.cnf.d

  ~]# mkdir -pv /var/{log,run,lib}/mysql/

2.2;编译

    ~]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc/mysql -DMYSQL_DATADIR=/data/mysql/data

    ~]# make && make install

2.3:配置文件

  ~]# cp /usr/local/mysql/support-files/my-default.cnf /etc/mysql/my.cnf

  ~]# vim /etc/mysql/my.cnf

------------------------------------------------------------------------------------------------

[mysqld]

# innodb_buffer_pool_size = 128M

# These are commonly set, remove the # and set as required.

basedir = /usr/local/mysql

datadir = /data/mysql

port = 3306

# server_id = .....

socket = /tmp/mysql.sock

# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.

# Adjust sizes as needed, experiment to find the optimal values.

# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M 

skip_name_resolve=on

innodb_file_per_table=on

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe]

log-error=/var/log/mysql/mysql.log

pid-file=/var/run/mysql/mysql.pid

------------------------------------------------------------------------------------------------

2.4:加入系统启动

    ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

    ~]# chkconfig --add mysqld

    ~]# chkconfig --list mysqld

2.5:初始化

    ~]#  /usr/local/mysql/scripts/mysql_install_db  --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/

2.6:加入环境变量

    ~]# echo 'export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/sbin/' >  /etc/profile.d/mysql.sh

    ~]# source  /etc/profile.d/mysql.sh

2.7:修改所属用户与组

  ~]# chown -R mysql:mysql  /usr/local/mysql

2.8:启动 停止与重启

  ~]# service mysqld (start | restart | stop)

2.9:进入mysql客户端

  ~]# mysql

三:用户授权

3.1:授权(172.0.0.1   localhost   远程     需要分别授权)

    grant all privileges on *.* to '用户名'@'允许的主机' identified by '密码' with grant option;

    flush privileges;

     grant all privileges on *.* to 'mysql'@'127.0.0.1' identified by '123456' with grant option;

     grant all privileges on *.* to 'mysql'@'localhost' identified by '123456' with grant option;

     grant all privileges on *.* to 'mysql'@'%' identified by '123456' with grant option;

     flush privileges;

mysql>use mysql;

mysql>update user set host = '%' where user = 'root';

mysql>select host, user from user;

mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;

mysql>FLUSH PRIVILEGES;

==============================================================

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

  /usr/local/mysql/bin/mysqladmin -u root password 'new-password'

  /usr/local/mysql/bin/mysqladmin -u root -h iZm5e35fwy8k6ujq6d272yZ password 'new-password'

Alternatively you can run:

  /usr/local/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test

databases and anonymous user created by default.  This is

strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

  cd . ; /usr/local/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

  cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at

  http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as /usr/local/mysql/my.cnf and

will be used by default by the server when you start it.

You may edit this file to change server settings

WARNING: Default config file /etc/mysql/my.cnf exists on the system

This file will be read by default by the MySQL server

If you do not want to use this, either remove it, or use the

--defaults-file argument to mysqld_safe when starting the server
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息