源碼安裝Mysql

ncurses-devel是cmake的依賴包mysql

安裝配置工具cmakenginx

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

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

建立運行用戶vim

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

解包,配置,編譯,安裝tcp

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

[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'

相關文章
相關標籤/搜索