(安裝版本8以上)
一、rpm包安裝
groupadd mysql
useradd -g mysql mysql
mkdir mysql
tar xf mysql-8.0.18-1.el7.x86_64.rpm-bundle\ \(1\).tar -c mysql
cd mysql
yum localinstall mysql-community-client-8.0.18-1.el7.x86_64.rpm mysql-community-server-8.0.18-1.el7.x86_64.rpm mysql-community-libs-8.0.18-1.el7.x86_64.rpm mysql-community-common-8.0.18-1.el7.x86_64.rpm
mysql> alter user 'root'@'localhost'identified by 'abc123@com'
;query ok, 0 rows affected (0.00 sec)
mysql> flush privileges;
query ok, 0 rows affected (0.00 sec)
二、通用二進位制安裝
安裝依賴包
yum install -y make gcc-c++ cmake bison-devel ncurses-devel readline-devel libaio-devel perl libaio wget lrzsz libnuma* bzip2 xz
vim /etc/selinux/config
selinux=disabled
setenforce 0
[root@sr2 ~]
# vim /etc/security/limits.conf
###custom
#* soft nofile 20480
* hard nofile 65535
* soft nproc 20480
* hard nproc 65535
[root@sr2 ~]
# vim /etc/sysctl.conf
#增加tcp支援的佇列數
net.ipv4.tcp_max_syn_backlog = 65535
#減少斷開連線時,資源**
net.ipv4.tcp_max_tw_buckets = 8000
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 10
#改變本地的埠範圍
net.ipv4.ip_local_port_range = 1024 65535
#允許更多的連線進入佇列
net.ipv4.tcp_max_syn_backlog = 4096
#對於只在本地使用的資料庫服務
net.ipv4.tcp_fin_timeout = 30
#埠監聽佇列
net.core.somaxconn=65535
#接受資料庫的速率
net.core.netdev_max_backlog=65535
net.core.wmem_default=87380
net.core.wmem_max=16777216
net.core.rmem_default=87380
net.core.rmem_max=16777216
[root@sr2 ~]
# sysctl -p
[root@sr2 ~]
# tar xf mysql-8.0.15-linux-glibc2.12-x86_64.tar.xz /opt/
做軟連線
[root@sr2 ~]
# ln -s /opt/mysql-8.0.15-linux-glibc2.12-x86_64/ /usr/local/mysql
使用者建立
[root@sr2 ~]
# groupadd mysql
[root@sr2 ~]
# useradd -g mysql mysql -d /home/mysql -s /sbin/nologin
修改許可權
[root@sr2 ~]
# chown -r mysql.mysql mysql/*
初始化資料庫 (初始化資料庫後在後面會生成個密碼,記住這個密碼,用它來進入資料庫)
[root@sr2 ~]
# cd /usr/loacl/mysql/
[root@sr2 mysql]
# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
[root@sr2 ~]
# if [ -f /etc/my.cnf ]; then mv /etc/my.cnf "/etc/my.cnf.`date +%y%m%d%h%m`.bak"; fi
[root@sr2 ~]
# vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
#skip-grant-tables
server_id=10
port = 3306
user = mysql
character-set-server = utf8
default_storage_engine = innodb
log_timestamps = system
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
pid-file = /usr/local/mysql/data/mysqld.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:10m:autoextend
####******************************=[log]********************=
log_error = /var/log/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /var/log/mysql-slow.log
sql_mode=no_engine_substitution,strict_trans_tables
cd /usr/local/mysql/
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
systemctl start mysqld
[root@sr2 ~]
# cd /etc/profile.d/
[root@sr2 profile.d]
# vim mysql.sh
export path=
$path:/usr/local/mysql/bin
[root@sr2 profile.d]
# source mysql.sh
MySQL資料庫改名的三種方法
前不久去面試,被問到innodb引擎的表如何改資料庫名,當時我也只回答了myisam改如何操作,被一些細節問題打敗,真是操蛋。如果表示myisam那麼可以直接去到資料庫目錄mv就可以。innodb完全不行,自己測試過,會提示相關表不存在。第一種方法 rename database olddbname...
MySQL資料庫改名的三種方法
innodb引擎的表如何改資料庫名?如果表示myisam那麼可以直接去到資料庫目錄mv就可以。innodb完全不行,自己測試過,會提示相關表不存在。第一種方法 rename database olddbname to newdbname 這個是5.1.7到5.1 23版本可以用的,但是官方不推薦,會...
三種方法檢視MySQL資料庫的版本
1 使用 v引數 首先我們想到的肯定就是檢視版本號的引數命令,引數為 v 大寫字母 或者 version 使用方法 d xampp mysql bin mysql v 或者d xampp mysql bin mysql version 2 使用 引數 其實這個有三個類似的引數 help i 大寫的i...