mysql系列(一.安装mysql)

来源:互联网 发布:淘宝店铺刷收藏 编辑:程序博客网 时间:2024/05/05 18:34

mysql 安装

标签(空格分隔): mysql


安装环境

linux 版本:centos 7
mysql 版本: mysql 5.6

通过rpm包安装(yum)

下载地址:http://dev.mysql.com/downloads/repo/yum/

安装指导:http://dev.mysql.com/doc/mysql-yum-rep-quick-guide/en/

安装步骤:

1.下载rmp包

wget http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
yum repolist all | grep mysql

3. 安装rpm包

sudo rpm -Uvh mysql-community-release-el6-n.noarch.rpm

4.安装mysql

sudo yum install mysql-community-server

5.启动mysql-server

sudo service mysqld start

6.停止mysql-server

sudo service mysqld stop

通过二进制包安装

1.下载二进制安装包

下载地址:http://dev.mysql.com/downloads/mysql/

下载

wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz

2.安装

解压文件:

tar zxvf mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz

创建安装文件夹:

mkdir -p  /web/mysql

复制文件到安装文件夹:

cp -r /home/download/mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz  /web/mysql

创建mysql用户:

groupadd mysqluseradd -r -g mysql mysql

查看安装帮助

./script/mysql_install_db --help
Usage: ./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 to set this to the location of the build directory where built files reside.--cross-bootstrap   For internal use.  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 from the given file name.--force              Causes mysql_install_db to run even if DNS does not work.  In that case, grant table entries that normally use hostnames will use IP addresses.--help               Display this help 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 for systems with working, updated my.cnf. Deprecated, will be removed in future version.--random-passwords   Create and set a random password for all root accounts and set the "password expired" flag, also remove the anonymous accounts.--rpm                For internal use.  This option is used 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 useful if your 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, useful for 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 for running mysqld.  Files and directories created by mysqld will be owned by this user.  You must be root to use this option.  By default mysqld runs using your current login name and files and directories that it creates will be owned by you.Any other options are passed to the mysqld program.

开始安装:

./script/mysql_install_db --basedir=/web/mysql --datadir=/web/mysql/data --user=mysql

修改配置文件:

[mysqld]basedir=/web/mysql/datadir=/web/mysql/data/socket=/web/mysql/run/mysql.sock[mysqld_safe]log-error=/web/mysql/log/mariadb.logpid-file=/web/mysql/run/mariadb.pid

创建运行文件夹:

mkdir -p /web/mysql/runmkdir -p /web/mysq/log

修改文件所有者:

chown -R mysql:mysql /web/mysql

3.注册服务

cp /web/mysql/support-files/mysql.server /etc/init.d/mysqld

之后根据mysql安装的位置修改脚本

chkconfig --add mysqld

4.mysqld 服务

a.启动

service mysqld start

b.关闭

service mysqld stop

5.安装中遇到的问题

a.

FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:Data::Dumper

解决办法:安装这个perl 模块

yum -y install perl-Data-Dumper

通过源码安装

1.下载源码

下载地址:http://dev.mysql.com/downloads/mysql/

下载

wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.26.tar.gz

2.编译

编译参数:http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html

常用编译参数及含义:

CMAKE_INSTALL_PREFIX=/usr/local/mysql #安装路径MYSQL_DATADIR=/usr/local/mysql/data #数据路径SYSCONFDIR=/etc #配置文件路径WITH_MYISAM_STORAGE_ENGINE=1 #编译MYISAM引擎WITH_INNOBASE_STORAGE_ENGINE=1 #编译INNODB引擎WITH_MEMORY_STORAGE_ENGINE=1 #编译MEMORY引擎WITH_READLINE=1 #加入readline库MYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock #sock文件路径MYSQL_TCP_PORT=3306 #默认端口ENABLED_LOCAL_INFILE=1 #启用本地导入数据文件WITH_PARTITION_STORAGE_ENGINE=1 #编译PARTITION引擎EXTRA_CHARSETS=all #字符扩展DEFAULT_CHARSET=utf8 #默认字符集DEFAULT_COLLATION=utf8_general_ci #默认字符排序

编译:

cmake \-DCMAKE_INSTALL_PREFIX=/home/mysql \-DMYSQL_DATADIR=/home/mysql/data \-DSYSCONFDIR=/etc \-DWITH_MYISAM_STORAGE_ENGINE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_MEMORY_STORAGE_ENGINE=1 \-DWITH_READLINE=1 \-DMYSQL_UNIX_ADDR=/home/mysql/run/mysql.sock \-DMYSQL_TCP_PORT=3306 \-DENABLED_LOCAL_INFILE=1 \-DWITH_PARTITION_STORAGE_ENGINE=1 \-DEXTRA_CHARSETS=all \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_cimake && make install

3.配置

参考二进制安装

4.安装中遇到的问题

a.

CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage

这是因为没有安装gcc 库

解决办法:

yum install gcc gcc-c++

b.

CMake Error at /usr/share/cmake/Modules/TestBigEndian.cmake:44 (message)

原因未知,解决办法:

删除 CMakeCache.txt文件后从新运行命令

c.

Could NOT find Curses (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH) 

缺少ncurses 库

解决办法:

yum install ncurses ncurses-devel

删除 CMakeCache.txt文件后从新运行命令

三种安装方式的优缺点

安装方式 优点 缺点 rpm包安装 1.安装简单,适合初学者学习使用 1.安装路径不灵活,默认路径不能修改,一台服务器只能MySQL安装一个 MySQL 二进制包安装 1.安装简单
2.可以地安装到任何路径下,灵活性好
3.一台服务器可以MySQL安装多个 MySQL 1.不能灵活定制编译参数 源码安装 1.在实际安装的操作系统进行可根据需要定制编译,最灵活
2.一台服务器可以安装多个 MySQL 1.安装过程较复杂, 学习成本高L
0 0
原创粉丝点击