正常情況下,ubuntu下在線安裝mysql都是采用apt方式,幾句命令就搞定了,網上教程很多,這里就不多說了,命令如下:
apt-get install mysql-server
apt-get install mysql-client
apt-get install libmysqlclient-dev
我這里要介紹的是非正常情況,由于我們服務器的原因,無法隨意連接外網,也就不能使用apt在線安裝方式,只能使用離線安裝,網上搜了一下,相關教程不是很多,這里介紹一下我的操作。
首先是相關文件下載,下載之后上傳到服務器,服務器環境:ubuntu16.04 64位
mysql免安裝包:http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
依賴包:http://archive.ubuntu.com/ubuntu/pool/main/liba/libaio/libaio1_0.3.110-2_amd64.deb
1. 安裝依賴
? ??dpkg -i libaio1_0.3.110-2_amd64.deb
2.?創建目錄存放數據庫文件data和日志log
? ??mkdir /mysql /mysql/data /mysql/log
3. 解壓mysql
? ??tar zxf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
4. 移到默認目錄
? ??mv mysql-5.7.17-linux-glibc2.5-x86_64??/usr/local/mysql
5. 增加用戶和組
? ??groupadd mysql
? ??useradd -g mysql mysql
6. 修改目錄權限
? ??chown -R mysql:mysql /usr/local/mysql /mysql
7. 創建配置文件
? ? vi /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
server_id=10
port = 3306
user = mysql
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /mysql/data
pid-file = /mysql/data/mysql.pid
max_connections = 1000
max_connect_errors = 1000
table_open_cache = 1024
max_allowed_packet = 128M
open_files_limit = 65535
#####====================================[innodb]==============================
innodb_buffer_pool_size = 1024M
innodb_file_per_table = 1
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_purge_threads = 2
innodb_flush_log_at_trx_commit = 1
innodb_log_file_size = 512M
innodb_log_files_in_group = 2
innodb_log_buffer_size = 16M
innodb_max_dirty_pages_pct = 80
innodb_lock_wait_timeout = 30
innodb_data_file_path=ibdata1:1024M:autoextend
#####====================================[log]==============================
log_error = /mysql/log/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /mysql/log/mysql-slow.log
sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
8. 添加執行權限
????chmod +x /usr/local/mysql/bin/*
9. 配置環境變量
? ??vim /etc/profile
????export PATH=$PATH:/usr/local/mysql/bin
? ? source /etc/profile
10. 配置啟動文件
? ??cp /usr/local/mysqlsupport-files/mysql.server /etc/init.d/mysql
11. 系統默認啟動
? ??update-rc.d mysql defaults
12. 初始化數據庫(5.7.6之后的版本初始化數據庫不再使用mysql_install_db)
? ??mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/home/fabric/mysql/data --innodb_undo_tablespaces=3 --explicit_defaults_for_timestamp
13.?啟動服務
? ??cd /usr/local/mysql/support-files
????./mysql.server start
? ??./mysql.server status(查看狀態,如果顯示【 * MySQL running】則說明啟動成功)
14.?可以在/mysql/log/mysql-error.log中查看root用戶的初始化密碼
? ??A temporary password is generated for root@localhost: *****************
15.?修改root密碼和遠程訪問權限
? ??mysql -u root -p
? ? 輸入14中查看的默認密碼
????SET PASSWORD = PASSWORD('your new password');
????update mysql.user set authentication_string=password('your new password') where user='root';
????GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your new password';
????FLUSH PRIVILEGES;
大功告成!!!