在 linux 上编译安装 mysql-5.6.28.tar.gz
http://www.mysql.com/
mysql下载地址:
http://www.mysql.com/downloads/mysql/#downloads
mysql 官方网站文档:
https://dev.mysql.com/doc/
01、准备工作
yum install-y gcc gcc-c++ cmake make ncurses ncurses-devel bison02、解压
tar zxf mysql-5.6.28.tar.gz03、编译
cmake . \-DCMAKE_INSTALL_PREFIX=/tmp/test/mysql \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_EXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
make-j 8
make install -j 8注意:
常见的CMAKE选项-DCMAKE_INSTALL_PREFIX=/usr/local/mysql MySQL安装目录-DWITH_INNOBASE_STORAGE_ENGINE=1安装InnoDB存储引擎-DWITH_MYISAM_STORAGE_ENGINE=1安装MyISAM存储引擎-DWITH_MEMORY_STORAGE_ENGINE=1安装内存存储引擎-DDEFAULT_CHARSET=utf8 默认编码设置成utf8-DDEFAULT_COLLATION=utf8_general_ci 默然校验规则是utf8_general_ci-DWITH_EXTRA_CHARSETS=all 支持其他所有的编码-DMYSQL_TCP_PORT=3306MySQL端口指定为3306-DMYSQL_UNIX_ADDR=/tmp/mysql.sock 指定SOCK文件路径-DMYSQL_DATADIR=/usr/local/mysql/data MySQL数据目录
make-j n 支持多线程编译(一般跟内核数相等)04、配置my.cnf
[root@rhel mysql]# pwd/tmp/test/mysql
mkdir conf
cp support-files/my-default.cnf conf/vim my.cnf 详情看下面的附属05、初始化数据库
useradd mysql
#注意--user 需要用root编译
./scripts/mysql_install_db --defaults-file=/tmp/test/mysql/my.cnf --user=mysql
./scripts/mysql_install_db --defaults-extra-file=/tmp/test/mysql/conf/my.cnf --user=mysql06、启动数据库
./bin/mysqld_safe --defaults-file=/tmp/test/mysql/my.cnf --user=mysql &./bin/mysqld_safe --defaults-extra-file=/tmp/test/mysql/conf/my.cnf --user=mysql &
07、设置密码
[root@rhel~]# ss -ln |grep 3333LISTEN0 80 :::3333 :::*./bin/mysqladmin -u root password '123123'
08、账户授权
grant all on*.* to 'mvpbang'@'%' identified by '123123';
flush privileges;09、设置系统环境变量
vim/etc/profile
export PATH=$PATH://tmp/test/mysql/bin
source/etc/profile
修改 rc.local ,让 mysql 开机自动运行
echo"mysqld_safe --defaults-extra-file=/tmp/test/mysql/conf/my.cnf --user=mysql &" >>/etc/rc.local10、基本命令的参数说明
[root@rhel mysql]# ./scripts/mysql_install_db --help
Usage: ./scripts/mysql_install_db [OPTIONS]--basedir=path The path to the MySQL installation directory.--builddir=path If using --srcdir with out-of-directory builds, you
will need toset thisto the location of the build
directorywherebuilt files reside.--cross-bootstrap For internaluse. Used when building the MySQL system
tables on a different host than the target.--datadir=path The path to the MySQL data directory.
If missing, the directory will be created, but its
parent directory must already exist and be writable.--defaults-extra-file=name
Read this file after the global files are read.--defaults-file=name Only read default options fromthe given file name.--force Causes mysql_install_db to run even ifDNS does not
work. In thatcase, grant table entries that
normally use hostnames will use IP addresses.--help Display thishelp and exit.--ldata=path The path to the MySQL data directory. Same as --datadir.--no-defaults Don't read default options from any option file.
--keep-my-cnf Don't try to create my.cnf based on template.
Useful forsystems with working, updated my.cnf.
Deprecated, will be removedinfuture version.--random-passwords Create and set a random password forall root accounts
andset the "password expired"flag,
also remove the anonymous accounts.--rpm For internal use. This option isused by RPM files
during the MySQL installation process.--skip-name-resolve Use IP addresses rather than hostnames when creating
grant table entries. This option can be usefulifyour DNS does not work.--srcdir=path The path to the MySQL source directory. This option
uses the compiled binaries and support files within the
source tree, usefulfor if you don't want to install
MySQL yet and just want to create the system tables.--user=user_name The login username to use forrunning mysqld. Files
and directories created by mysqld will be owned bythisuser. You must be root to usethis option. By defaultmysqld runsusingyour current login name and files and
directories that it creates will be owned by you.
Any other options are passed to the mysqld program.
[root@rhel mysql]# ./bin/mysqld_safe --help
Usage: ./bin/mysqld_safe [OPTIONS]--no-defaults Don't read the system defaults file
--defaults-file=FILE Use the specified defaults file--defaults-extra-file=FILE Also use defaults fromthe specified file--ledir=DIRECTORY Look for mysqld inthe specified directory--open-files-limit=LIMIT Limit the number of open files--core-file-size=LIMIT Limit core files to the specified size--timezone=TZ Set the system timezone--malloc-lib=LIB Preload shared library LIB ifavailable--mysqld=FILE Use the specified file asmysqld--mysqld-version=VERSION Use "mysqld-VERSION" asmysqld--nice=NICE Set the scheduling priority of mysqld--plugin-dir=DIR Plugins are under DIR or DIR/VERSION, ifVERSIONisgiven--skip-kill-mysqld Don't try to kill stray mysqld processes
--syslog Log messages to syslog with 'logger'
--skip-syslog Log messages to error log (default)--syslog-tag=TAG Pass -t "mysqld-TAG" to 'logger'All other options are passed to the mysqld program.