飛騰、龍芯、源碼編譯mysql數據庫

公司不能連接外網,要安裝mysql數據庫只能安裝包安裝,目前公司在龍芯服務器上安裝,也就是mips64el架構上安裝,mysql在此不適配,所以要源碼編譯安裝mysql。

在此用編譯mysql,n多次,幾天的時間過去了,一直報錯,報錯解決再報錯,再解決,實在不行。需要修改源碼裏面的東西,後來瞭解到mips64el,不支持mysql,在龍芯上只能用mariadb。其實都是一樣,但龍芯上就是不支持,沒辦法。重新換爲mariadb來編譯,也是嘗試了n多次,終於成功了。在此將詳細過程展示如下:

官方下載mariadb源碼   https://downloads.mariadb.org/

直接下載源碼包  https://downloads.mariadb.org/mariadb/5.5.60/

安裝一些依賴包 gcc、g++、bison、make、cmake、libncurses5-dev

預編譯:
cmake  -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
    -DSYSCONFDIR=/etc \
    -DDEFAULT_CHARSET=utf8 \
    -DDEFAULT_COLLATION=utf8_general_ci \
    -DWITH_EXTRA_CHARSETS=all \

# 注:
#第一行是mysql主程序安裝目錄
#第二行是配置文件目錄
#第三行默認字符集爲utf8
#第四行默認的字符集效對規則
#第五行安裝所有字符集

編譯安裝:
    make && make install 

安裝完成之後:make clean   清除編譯過程中產生的臨時文件和配置過程中產生的文件    至此,軟件安裝完成


創建mysql用戶:
                      groupadd mysql
[ root@localhost / ]# useradd -M -s /sbin/nologin -g mysql mysql


MariaDB配置文件創建及更改。

[ root@localhost / ]# cp support-files/my-medium.cnf /etc/my.cnf   
#複製配置文件
[ root@localhost / ]# cp support-files/mysql.server  /etc/init.d/mysqld  將它放在init.d中以讓其自動啓動
#複製啓動腳本
[ root@localhost / ]# vim /etc/my.cnf 
basedir=/usr/local/mysql
datadir = /usr/local/mysql/data/  
#指定數據庫路徑,不然無法啓動mysql
innodb_file_per_table = on
 #設置後當創建數據庫的表的時候表文件都會分離開,方便複製表,不開啓創建的表都在一個文件
skip_name_resolve = on  
#跳過名稱反解,Mysql每次使用客戶端鏈接時都會把ip地址反解成主機名


執行開機自動啓動系統服務:update-rc.d mysqld defaults             卸載腳本的方法(需進入init.d中):update-rc.d -f XXX remove

    用法:首先確保腳本已在/etc/init.d目錄下,然後用:
         update-rc.d XXX defaults NN 命令(NN爲啓動順序),將
         腳本添加到初始化執行的隊列中去。按照自己的需要啓動腳本的順序來指定相應的修改
    注意:如果腳本需要用到網絡,則NN需要設置一個比較大的數字,如99

設置開機自啓動的方法:chkconfig --add test
      重啓後永久生效:chkconfig test on/off    

安裝數據庫系統表:
./mysql_install_db  --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

啓動mysql數據: /usr/local/mysql/bin/mysqld_safe &

安全初始化mysql及設定:  /usr/local/mysql/bin/mysql_secure_installation
執行步驟:
   /usr/local/mysql/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):     #回車
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y  #是否設置root密碼
New password:   
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]    #刪除匿名賬號
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]   #是否禁止root賬號遠程登錄,生產環境中一定要禁止
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y    #是否清除測試數據庫
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y  #重載
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

測試能否登錄入數據庫
root@9d3ce8f77312:/usr/local/mysql/bin# mysql -u root -p111111
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 5.5.60-MariaDB Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> 


開機即啓動mysql 以及添加到全局變量需要每次更新
在/etc/.bashrc裏面添加
    source /etc/profile
   /etc/init.d/mysqld start
達到開機即啓動

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章