1)官网下载地址:https://dev.mysql.com/downloads/mysql/
此处下载的是 mysql-boost-5.7.24.tar.gz
2)安装依赖包
yum list|grep ncurses-devel
yum -y install make gcc-c++ cmake bison-devel ncurses-devel
3)创建安装目录
mkdir /usr/local/mysql 安装目录
mkdir -p /data/3306/data 存放数据目录
mkdir /data/3306/binlog/
4)编译
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/3306/data \
-DSYSCONFDIR=/data/3306 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/data/3306/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci
编译会报错
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:507 (INCLUDE)
-- Configuring incomplete, errors occurred!
See also "/root/mysql-5.7.24/CMakeFiles/CMakeOutput.log".
See also "/root/mysql-5.7.24/CMakeFiles/CMakeError.log".
解决方法:
mkdir /usr/local/boost
cd /usr/local/boost
wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
tar zxvf boost_1_59_0.tar.gz
重新编译并加最后一条参数
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ 安装根目录
-DMYSQL_DATADIR=/data/3306/data \ 数据存储目录
-DSYSCONFDIR=/data/3306 \ 配置文件(my.cnf)目录
-DWITH_MYISAM_STORAGE_ENGINE=1 \ 编译myisam存储引擎,默认的存储引擎,不加也可以
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ 支持InnoDB存储引擎,这个也是默认安装的
-DWITH_MEMORY_STORAGE_ENGINE=1 \ 支持MEMORY引擎
-DWITH_READLINE=1 \ 使用readline功能
-DMYSQL_UNIX_ADDR=/data/3306/mysql.sock \ sock存放到/data/3306目录
-DMYSQL_TCP_PORT=3306 \ 数据库端口
-DENABLED_LOCAL_INFILE=1 \ 可以使用load data infile命令从本地导入文件
-DWITH_PARTITION_STORAGE_ENGINE=1 \ 安装数据库分区
-DEXTRA_CHARSETS=all \ 支持所有字符集
-DDEFAULT_CHARSET=utf8mb4 \ 默认字符集
-DDEFAULT_COLLATION=utf8mb4_general_ci \ 设置默认效验字符集排序规则,要和DDEFAULT_CHARSET一起用
-DWITH_BOOST=/usr/local/boost 从MySQL 5.7.5开始Boost库是必需的
5)安装
make && make install
make clean
6)添加用户和组
groupadd mysql
useradd -g mysql mysql
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /data/3306
7)实例初始化
cd /usr/local/mysql
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306/data/ 初始化完了需要记住root密码
出现以下说明初始化成功
2018-11-12T01:25:29.316210Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-11-12T01:25:30.314274Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-11-12T01:25:30.441468Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-11-12T01:25:30.512508Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: d7df9433-e619-11e8-804b-00163e0851f0.
2018-11-12T01:25:30.517175Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened.
2018-11-12T01:25:30.517899Z 1 [Note] A temporary password is generated for root@localhost: _1ahqhzYqtMd
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
SET PASSWORD = PASSWORD('*********');
在5.7.6之前初始化的方法是:bin/mysql_install_db
5.7.6之后的版本初始化数据库不再使用mysql_install_db,而是使用: bin/mysqld --initialize
8)配置数据库
复制启动文件
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
cp bin/my_print_defaults /usr/bin/
修改启动脚本
vi /etc/init.d/mysqld
修改项为图中方框的部分
修改mysql配置项
vi /etc/my.cnf
配置如下:
[mysqld]
basedir = /usr/local/mysql
datadir = /data/3306/data/
socket = /data/3306/mysql.sock
user = mysql
tmpdir = /data/3306/
symbolic-links=0
[mysqld_safe]
log-error = /data/3306/data/error.log
pid-file = /data/3306/data/mysql.pid
启动mysql
service mysqld start
ps -ef|grep mysql
root 2644 488 0 10:21 pts/1 00:00:00 grep --color=auto mysql
root 24581 1 0 00:19 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/3306/data/ --pid-file=/data/3306/data//k8s-test-master.pid
mysql 24769 24581 0 00:19 ? 00:00:08 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/3306/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/3306/data/error.log --pid-file=/data/3306/data//k8s-test-master.pid --socket=/data/3306/mysql.sock
9)修改密码
现在是可以登录了但发现需要密码,原来5.7后MySQL会生成一个随机密码,
我没有找到存放密码的文件,就只能去强制修改密码了。
在my.cnf中加上skip-grant-tables后 service mysqld restart
修改完成后发现可以不用密码直接登录
登录后执行
update mysql.user set authentication_string=password(‘123456’) where user=‘root’;
flush privileges;
执行成功后将my.cnf 文件改回去,重启MySQL,使用新密码登录,MySQL已安装完成。
安装完mysql 之后,登陆以后,不管运行任何命令,总是提示这个
mysql> select version();
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
解决方法如下三步:
step 1: SET PASSWORD = PASSWORD(‘your new password’);
step 2: ALTER USER ‘root’@‘localhost’ PASSWORD EXPIRE NEVER;
step 3: flush privileges;
完成以上三步退出再登,使用新设置的密码就行了,以上除了第一步修改成新密码外,其他原样输入即可