[數據庫]Ubuntu Linux/Kylin: 安裝MySQL


1 文由

由於安裝環境較為特殊,實在折煞人也。而此環境的網絡博客/教程偏少,覺得有必要記錄一下。

2 環境

安裝主機不支持聯網 即 不支持APT/APT-GET等傻瓜式的在線安裝方式。

  • 硬件架構: AARCH64(ARM64架構的V8狀態)
  • OS: Kylin(國產操作系統:銀河麒麟)
    • 基於 Ubuntu Linux內核
root@Kylin:~# cat /proc/version
Linux version 4.15.0-72kord1-generic (root@Kylin) (gcc version 5.4.0 20160609 (Ubuntu/Linaro 5.4.0-6kord1~16.04.10)) #72kord1 SMP Tue Jan 14 20:23:52 CST 2020

root@Kylin:~# uname -a
Linux Kylin 4.15.0-72kord1-generic #72kord1 SMP Tue Jan 14 20:23:52 CST 2020 aarch64 aarch64 aarch64 GNU/Linux

3 安裝過程

  • 下載、上傳: 支持ARM64的MySQL安裝包到目標主機
https://launchpad.net/ubuntu/bionic/arm64/mysql-server
https://launchpad.net/ubuntu/bionic/arm64/mysql-server/5.7.27-0ubuntu0.18.04.1
  • 安裝: MySQL
dpkg -i mysql-server_5.7.27-0ubuntu0.18.04.1_all.deb
  • 初次登陸: MySQL
    登陸前,需配置MySQL的socket通信文件(mysqld.sock)
sudo mysql -u root -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

解決方法: 
+ 創建sock文件
      mkdir /var/run/mysqld/
      touch /var/run/mysqld/mysqld.sock
+ 修改文件所有者
      chown mysql /var/run/mysqld/mysqld.sock
+ 重啟服務
      service mysql restart
  • 查看用戶(debian-sys-maint)初始登陸密碼
cat /etc/mysql/debian.cnf
      user     = debian-sys-maint
      password = JALJKBhjpqCfgeIPyo
  • 再次登陸
root@Kylin:~# mysql -udebian-sys-maint -pJALJKBhjpqCfgeIPyo
  • 修改: 密碼
show databases;
use mysql;
update user set authentication_string=PASSWORD("123456") where user='root';
update user set plugin="mysql_native_password";
flush privileges;
quit;
	
mysql -uroot -p      #輸入上面查到的臨時密碼
alter user 'root'@'localhost' identified by '123456';
create user 'root'@'%' IDENTIFIED BY '123456';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
  • 配置: 支持遠端連接
root@Kylin:~# vi /etc/mysql/mysql.conf.d/mysqld.cnf
root@Kylin:~# mysql -u root -p
    # Instead of skip-networking the default is now to listen only on
    # localhost which is more compatible and is not less secure.
    # bind-address            = 127.0.0.1
    bind-address              = 0.0.0.0
  • 配置: mysql系統級配置
    為什么用這種繁瑣、效率低下的配置方式?
    因為N次嘗試直接配置mysqld.cnf文件后,再重啟MySQL均失敗,實在不得已而為之。

修改/etc/mysql/mysql.conf.d/mysqld.cnf(等同於配置其他常見主流教程中的/etc/mysql/my.cnf)配置:

查找 OS配置文件: find / -name "my.cnf"
查看 MySQL配置項: show variables like 'datadir';

    set global thread_cache_size=64;
    set global max_allowed_packet=104857600;
    	100M = 100*1024*1024 = 104857600
    set global key_buffer_size = 629145600;
    	600M = 600*1024*1024 = 629145600
    set global query_cache_size = 268435456;
    	256M = 256*1024*1024 = 268435456
    set global max_connections=500;
    set global table_open_cache = 1024;
        # table_cache 在5.1.3以后叫做 table_open_cache
    set global innodb_buffer_pool_size=2147483648;
    	2048M = 2048*1024*1024 = 2147483648
    set global collation_server=utf8_bin;
    set global sql_mode='NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES';
    set global sort_buffer_size = 6144;
    	6M = 6*1024= 6144
    set global read_buffer_size = 6144;
        6M = 6*1024= 6144
    set global read_rnd_buffer_size = 8192;
    	8M = 8*1024 = 8192
    set global myisam_sort_buffer_size = 65536;
		64M = 64*1024= 65536
    set global innodb_flush_log_at_trx_commit = 2;    
    
    [read only] 【只能通過配置文件修改,本次安裝沒有配置成功如下配置項】
    set global datadir='/var/lib/mysql/' 【有改動】
    set global symbolic-links=0;
    set global log_error='/var/log/mysql/error.log'; 【有改動】
    set global skip_name_resolve;
        # 能讓MySQL登陸鏈接變快速      # 0 關閉支持符號鏈接
 	set global lower_case_table_names=0;
    set global innodb_log_file_size = 1073741824;
    	1024M = 1024*1024*1024 = 1073741824
    set global innodb_log_files_in_group = 3;
  • 配置: MySQL端口
vi /etc/mysql/mysql.conf.d/mysqld.cnf
      [mysqld]
      port = 1314
  • 配置: 字符集編碼
【服務端字符集】
set global character_set_server=utf8; 
或(推薦↓)
vi /etc/mysql/mysql.conf.d/mysqld.cnf
      [mysqld]
      character-set-server=utf8

【數據庫字符集】[可選]
set global character_set_database=utf8;

【客戶端字符集】
vi /etc/mysql/conf.d/mysql.cnf 
      [mysql]
      no-auto-rehash
      default-character-set=utf8

查看 MySQL字符集編碼: show variables like '%character%';

+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
  • 配置MySQL服務到系統服務中
systemctl start mysql.service

上述操作失敗時,可進行的輔助操作↓

cat /var/log/syslog

service mysql restart
service mysql status

4 文獻: 參考與推薦


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM