澳门在线威尼斯官方 > 电脑数据库 > 源码包方式,11编译安装以及修改root密码小结

原标题:源码包方式,11编译安装以及修改root密码小结

浏览次数:67 时间:2019-11-16

缺点:后期升级不方便,生产中建议RPM包方式安装

系统是cenos6.7 64位的,默认mysql5.7.11下载到/usr/local/src,安装目录在/app/local/mysql目录下,mysql数据放置目录/app/local/data。mysql从5.1后采用cmake方式编译安装,所以要先编译安装cmake工具,也可以采用yum方式安装cmake。从mysql5.7开始编译安装需要boost库的支持,所以也要下载boost库

 

CentOS7默认安装了和MySQL有兼容性的MariaDB数据库,在我们安装MySQL5.7之前为了避免发生冲突首先删除MariaDB。

# rpm -qa | grep maria

# yum remove mariadb-libs -y

一、基于官方源码包安装

下载 mysql-5.7.22.tar.gz

安装cmake

# yum -y install cmake

# tar -zxvf mysql-5.7.22.tar.gz -C /usr/src

# cd /usr/src/mysql-5.7.22

# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/var/lib/mysql -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DENABLED_LOCAL_INFILE=1 -DWITH_EXTRA_CHARSETS=all -DMYSQL_USER=mysql

-- Running cmake version 2.8.11
-- Configuring with MAX_INDEXES = 64U
-- CMAKE_GENERATOR: Unix Makefiles
-- SIZEOF_VOIDP 8
-- MySQL 5.7.22
-- Packaging as: mysql-5.7.22-Linux-x86_64
-- Downloading boost_1_59_0.tar.gz to /usr/local/boost
-- [download 100% complete]
-- Download failed, error: 35;"SSL connect error"
CMake Error at cmake/boost.cmake:194 (MESSAGE):
  You can try downloading
 
  manually using curl/wget or a similar tool
Call Stack (most recent call first):
  CMakeLists.txt:506 (INCLUDE)

-- Configuring incomplete, errors occurred!

解决:下载boost_1_59_0.tar.gz,放在/usr/local/boost下

# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/var/lib/mysql -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DENABLED_LOCAL_INFILE=1 -DWITH_EXTRA_CHARSETS=all -DMYSQL_USER=mysql -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost

...

-- Check size of wint_t
-- Check size of wint_t - done
-- 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:197 (MYSQL_USE_BUNDLED_EDITLINE)
  CMakeLists.txt:534 (MYSQL_CHECK_EDITLINE)

-- Configuring incomplete, errors occurred!

解决:

#yum -y install ncurses-devel

# rm -rf /usr/src/mysql-5.7.22/CMakeCache.txt

 

# gmake

# make install

 

安装之后的一些配置:

# cd /usr/local/mysql/support-files/
]# ll mysql.server
-rwxr-xr-x 1 root root 10569 Apr 20 11:11 mysql.server
# cp mysql.server /etc/init.d/mysql

# cd /var/lib/
# mkdir mysql
# chown mysql. mysql
# vi /etc/my.cnf

[mysqld]
basedir = /usr/local/mysql
datadir = /var/lib/mysql
port = 3306
socket = /tmp/mysqld.sock

mysql_install_db 被废弃了,取而代之的是 mysqld –initialize

# /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize  --datadir=/var/lib/mysql --basedir=/usr/local/mysql --user=mysql
2018-04-20T07:49:28.669315Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-04-20T07:49:29.022395Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-04-20T07:49:29.090056Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-04-20T07:49:29.151786Z 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: 5ae072ef-446f-11e8-aa2d-0050568810c7.
2018-04-20T07:49:29.153819Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-04-20T07:49:29.155286Z 1 [Note] A temporary password is generated for root@localhost: ;1ruP:p6R8te
# ll /var/lib/mysql/
总用量 110628
-rw-r----- 1 mysql mysql       56 4月  20 15:49 auto.cnf
-rw-r----- 1 mysql mysql      417 4月  20 15:49 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 4月  20 15:49 ibdata1
-rw-r----- 1 mysql mysql 50331648 4月  20 15:49 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 4月  20 15:49 ib_logfile1
drwxr-x--- 2 mysql mysql     4096 4月  20 15:49 mysql
drwxr-x--- 2 mysql mysql     8192 4月  20 15:49 performance_schema
drwxr-x--- 2 mysql mysql     8192 4月  20 15:49 sys

# systemctl start mysql
# ps -ef|grep mysql

# vi ~/.bash_profile

PATH=$PATH:$HOME/bin:/usr/local/mysql/bin

# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

配置文件中添加如下一行,跳过密码验证

# cat /etc/my.cnf
[mysqld]

skip-grant_tables

重启MySQL

# systemctl restart mysql

# mysql

mysql> update mysql.user set authentication_string=password('oracle') where user='root' ;

再次重启MySQL

# systemctl restart mysql

# mysql

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql> set password=password('123456');

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

 

二、基于官方源代码RMP构建自定义MySQLRPM(一般用于企业内部开发,生产中还是MySQL包的方式安装)

创建一个普通用户,用于构建自定义的RPM包

# useradd tubeliu
# cp mysql-community-5.7.22-1.el7.src.rpm /home/tubeliu/
# chown tubeliu.tubeliu /home/tubeliu/ -R
# yum list | grep rpm-build
      
# yum -y install rpm-build

# su - tubeliu
 ls
mysql-community-5.7.22-1.el7.src.rpm
$ rpmbuild ~
错误:文件 /home/tubeliu 不是常规文件。
$ ls
mysql-community-5.7.22-1.el7.src.rpm  rpmbuild
$ cd rpmbuild/
$ ls
BUILD  BUILDROOT  RPMS  SOURCES  SPECS  SRPMS
$ cd ..
$ ls
mysql-community-5.7.22-1.el7.src.rpm  rpmbuild
$ rpm -ivh mysql-community-5.7.22-1.el7.src.rpm
正在升级/安装...
   1:mysql-community-5.7.22-1.el7     ################################# [100%]
$ cd rpmbuild/
$ ls
BUILD  BUILDROOT  RPMS  SOURCES  SPECS  SRPMS
$ ls -R
.:
BUILD  BUILDROOT  RPMS  SOURCES  SPECS  SRPMS

./BUILD:

./BUILDROOT:

./RPMS:

./SOURCES:
boost_1_59_0.tar.bz2  filter-requires.sh   mysql-5.7.22.tar.gz
filter-provides.sh    mysql-5.6.37.tar.gz

./SPECS:
mysql.spec

./SRPMS:
$ cd SPECS/
$ vi mysql.spec
$ rpmbuild -bb mysql.spec

 

#wget

#wget

#wget

如果没有mysql用户则新建mysql用户。

#groupadd mysql

#useradd -g mysql mysql -s /bin/false

创建相应的目录

#mkdir -p /app/local/{mysql,data}

#mkdir  /usr/local/boost

编译安装cmake

#tar zxvf cmake-3.1.3.tar.gz

#cd cmake-3.1.3

#./configure

#make && make install

#cd ../

将boost库解压到/usr/local/boost目录下

#tar zxvf boost_1_59_0.tar.gz

#cd boost_1_59_0/

#mv ./* /usr/local/boost/

#cd ../

编译安装mysql5.7.11

#tar zxvf mysql-5.7.11.tar.gz

本文由澳门在线威尼斯官方发布于电脑数据库,转载请注明出处:源码包方式,11编译安装以及修改root密码小结

关键词:

上一篇:没有了

下一篇:没有了