环境准备:
mysql 安装包:mysql-boost-5.7.12.tar.gz
系统版本:CentOS Linux release 7.2.1511 (Core)
一 清理环境
yum list installed *mysql*
yum remove installed *mysql*
二 创建mysql组和用户
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
注:mysql 用户设置为禁止登陆,分配有限资源,以便限制访问
三 创建数据库使用目录
mkdir /usr/local/mysql
mkdir -p /data/mysql_data
chown -R mysql:mysql /data/mysql_data
四 编译安装
1)安装编译环境
yum install cmake make gcc gcc-c++ ncurses-devel
2)cmake 生成 makefile 以供指导安装
tar -xvf mysql-boost-5.7.12.tar.gz
cd mysql-5.7.12
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql_data -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=boost/boost_1_59_0/
注:cmake 使用你的编译解释:
注:这里遇到的问题:
错误一:
-- Running cmake version 2.8.11
-- Could NOT find Git (missing: GIT_EXECUTABLE)
-- Configuring with MAX_INDEXES = 64U
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error: your C compiler: "CMAKE_C_COMPILER-NOTFOUND" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
CMake Error at cmake/os/Linux.cmake:41 (MESSAGE):
Unsupported compiler!
Call Stack (most recent call first):
CMakeLists.txt:162 (INCLUDE)
解决方法:yum install gcc gcc-c++
错误二:
-- Could not find (the correct version of) boost.
-- MySQL currently requires boost_1_59_0
CMake Error at cmake/boost.cmake:81 (MESSAGE):
You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=
This CMake script will look for boost in . If it is not there,
it will download and unpack it (in that directory) for you.
If you are inside a firewall, you may need to use an http proxy:
export http_proxy=http://example.com:80
Call Stack (most recent call first):
cmake/boost.cmake:238 (COULD_NOT_FIND_BOOST)
CMakeLists.txt:451 (INCLUDE)
解决方法:
从MySQL 5.7.5开始Boost库是必需的
下载 mysql-boost-5.7.12.tar.g 在 cmake 指定参数 -DWITH_BOOST=boost/boost_1_59_0/
或直接cmake指定参数 -DDOWNLOAD_BOOST=1 -DWITH_BOOST= 系统会下载 boost
错误三:
-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:64 (MESSAGE):
Curses library not found. Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:107 (FIND_CURSES)
cmake/readline.cmake:181 (MYSQL_USE_BUNDLED_EDITLINE)
CMakeLists.txt:479 (MYSQL_CHECK_EDITLINE)
解决方法:yum install ncurses-devel
3)编译安装
make && make install
4)mysql 命令添加到环境变量中
vi /etc/profile
source /etc/profile
# mysql env
PATH=/usr/local/mysql/bin:$PATH
export PATH
五 安装 设置mysql 服务 ,并开机自启动
chown -R mysql.mysql /usr/local/mysql/
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
#增加一个mysqld 服务器
chkconfig --add mysqld
#设置MySQL服务器在运行级别2345上运行
chkconfig mysql on
chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
六 安装数据库
cd /usr/local/mysql
mkdir -p /data/mysql_data
./bin/mysql_install_db --user=mysql --datadir=/data/mysql_data
echo $?
七 创建配置文件
vim /etc/my.cnf(注:以下配置仅供参考)
[mysqld]
datadir=/data/mysql_data
socket=/usr/local/mysql/mysql.sock
user=mysql
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
key_buffer_size = 8144M
table_cache_size = 1024M
read_buffer_size = 128M
sort_buffer_size = 32M
query_cache_size = 100M
thread_cache_size = 16
thread_concurrency = 32
max_heap_table_size = 400M
tmp_table_size = 400M
max_connections = 500
# The end
#
说明:
八 启动数据库
/etc/init.d/mysqld start
或
service mysqld start
[root@f823a1ce09a8 local]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
[root@f823a1ce09a8 local]# ps -aux | grep mysql
root 20149 0.0 0.1 11772 2772 ? S 08:13 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql_data --pid-file=/data/mysql_data/f823a1ce09a8.pid
mysql 20439 0.7 9.8 2465512 201608 ? Sl 08:13 0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql_data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/data/mysql_data/f823a1ce09a8.pid --socket=/usr/local/mysql/mysql.sock
root 20468 0.0 0.0 9044 804 ? S+ 08:13 0:00 grep --color=auto mysql
九 登陆数据库
mysql5.7会生成一个初始化密码,而在之前的版本首次登陆不需要登录
查看root 密码
[root@f823a1ce09a8 mysql_data]# cat /root/.mysql_secret
# Password set for user 'root@localhost' at 2016-05-09 08:38:54
ia8GCm:d>(bo
mysql -u root -p 登陆
十 修改权限
1)修改密码
修改root密码:
mysqladmin -u root -p -h CentOS-StandAlone password 'newpassword'
或 登陆数据库 mysql 数据库
update user set password=password('newpassword') where user='root'
2)授权
#完全授权,密码:123456
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9';
flush privileges;
Query OK, 0 rows affected (0.00 sec)
#允许8.8.8.1上的访问,密码:123456
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'8.8.8.1' IDENTIFIED BY PASSWORD'*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9';
flush privileges;
Query OK, 0 rows affected (0.00 sec)
附录:
(一)Mysql有两种连接方式:
(1),TCP/IP
(2),socket
对mysql.sock来说,其作用是程序与mysqlserver处于同一台机器,发起本地连接时可用。
例如你无须定义连接host的具体IP得,只要为空或localhost就可以。
在此种情况下,即使你改变mysql的外部port也是一样可能正常连接。
因为你在my.ini中或my.cnf中改变端口后,mysql.sock是随每一次 mysql server启动生成的。已经根据你在更改完my.cnf后重启mysql时重新生成了一次,信息已跟着变更。
(二) chkconfig
用于管理/etc/init.d 下的服务脚本
--add name
增加一个新的服务,让chkconfig指令得以管理它,并同时在系统启动的叙述文件内增加相关数据。
--del name
删除一个服务
--list name
显示服务的情况
--level:指定读系统服务要在哪一个执行等级中开启或关毕
注:运行级别:
等级0表示:表示关机
等级1表示:单用户模式
等级2表示:无网络连接的多用户命令行模式
等级3表示:有网络连接的多用户命令行模式
等级4表示:不可用
等级5表示:带图形界面的多用户模式
等级6表示:重新启动