源码安装Mysql

ncurses-devel是cmake的依赖包

安装配置工具cmake

[root@nginx~]# rpm -q mysql mysql-server mariadb mairadb-server

[root@nginx~]# yum -y install ncurses-devel cmake

创建运行用户

[root@nginx~]#useradd -M -s /sbin/nologin mysql

解包,配置,编译,安装

[root@nginx~]# tar xf mysql-5.7.24.tar.gz -C /usr/src/

[root@nginx~]# cd /usr/src/mysql-5.7.24/

[root@nginx mysql-5.7.24]#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc&& make && make install

  • -DCMAKE_INSTALL_PREFIX=/usr/local/mysql //数据库程序安装目录
  • -DDEFAULT_CHARSET=utf8 //指定字符集编码
  • -DDEFAULT_COLLATION=utf8_general_ci //默认的字符集校对规则,utf8_general_ci适用于utf-8字符集的通用规则
  • -DWITH_EXTRA_CHARSETS=all //指定额外支持的字符集编码
  • -DSYSCONFDIR=/etc //指定配置文件存放目录

报错处理:

------------------------------------------------------------------------------CMake Error at cmake/boost.cmake:81 (MESSAGE):

You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>

 

This CMake script will look for boost in <directory>. 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 "/usr/src/mysql-5.7.24/CMakeFiles/CMakeOutput.log".

See also "/usr/src/mysql-5.7.24/CMakeFiles/CMakeError.log".

------------------------------------------------------------------------------

 

解决办法:

a.在/usr/local下创建一个名为boost的文件夹

[root@nginx~]#mkdir /usr/local/boost

 

b.进入目录并下载boost

[root@nginx~]# cd /usr/local/boost

[root@nginxboost]#wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz

 

c.解压boost

[root@nginxboost]# tar xf boost_1_59_0.tar.gz

 

d.继续cmake,添加上红色部分

[root@nginx mysql-5.7.24]#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc -DWITH_BOOST=/usr/local/boost && make && make install

2)安装后的调整

对数据库目录进行权限设置

[root@nginx~]# cd /usr/local/mysql/

[root@nginxmysql]#chown -R mysql:mysql ./                      

 

建立配置文件(CentOS7系统默认支持MariaDB数据库,系统默认的/etc/my.cnf配置文件是MariaDB的配置文件 )

[root@nginxmysql]# vim /etc/my.cnf

[mysqld]

datadir=/usr/local/mysql/data

socket=/tmp/mysql.sock

 

[mysqld_safe]

log-error=/usr/local/mysql/data/mysql.log

pid-file=/usr/local/mysql/data/mysql.pid

 

3)初始化数据库

[root@nginxmysql]# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize

2018-12-08T01:51:39.798903Z 1 [Note] A temporary password is generated for root@nginx: TvC:Rm1ZlxtG

  • --basedir=/usr/local/mysql/ //指定安装目录(产品目录)
  • --datadir=/usr/local/mysql/data //指定数据目录
  • --user=mysql //指定用户身份

 

4)设置环境变量

[root@nginx mysql-5.7.24]# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile

[root@nginx mysql-5.7.24]#  source /etc/profile

 

5)添加系统服务

添加MySQL为系统服务,以便通过systemctl命令进行管理

[root@nginx mysql-5.7.24]# cp support-files/mysql.server /etc/init.d/mysqld

[root@nginx mysql-5.7.24]#chmod +x /etc/init.d/mysqld                                                                   

/etc/init.d/mysqld start

[root@nginx~]# netstat -lnpt | grep mysqld

tcp6 0 0 :::3306 :::* LISTEN 2520/mysqld

后期修改数据库用户的密码:

[root@nginx~]#mysqladmin -uroot -p'TvC:Rm1ZlxtG' password '123456'

posted @ 2019-10-09 14:33  IT民工9527  阅读(307)  评论(0编辑  收藏  举报