Liunxnode
A 安裝mysql
安裝版本:mysql-5.6.26.tar.gzc++
a1 卸載相關包:sql
rpm -qa | grep mysql 數據庫
rpm -e --nodeps 名稱vim
a2 新增用戶及用戶組socket
[root@cas ~]# groupadd mysqlide
[root@cas ~]# useradd -r -g mysql mysqlui
a3 建立目錄spa
[root@cas ~]# groupadd mysql
[root@cas ~]# useradd -r -g mysql mysql
[root@cas ~]# mkdir -p /usr/local/mysql
[root@cas ~]# mkdir -p /usr/local/mysql/src
[root@cas ~]# mkdir -p /home/mysql
[root@cas ~]# mkdir -p /home/mysql/data
[root@cas ~]# mkdir -p /home/mysql/logs
[root@cas ~]# mkdir -p /home/mysql/temp
[root@cas ~]# vim /etc/profile
a4 添加環境變量
[root@cas ~]# vim /etc/profile
添加:PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
當即生效:
[root@cas ~]# source /etc/profile
a5 安裝依賴包(需聯網)
[root@cas ~]# yum install make cmake gcc gcc-c++ bison bison-devel ncurses ncurses-devel antoconf automake -y
a6 將壓縮包上傳至/usr/local/mysql/src,並解壓
[root@cas ~]# cd /usr/local/mysql/src/
[root@cas src]# tar zxf mysql-5.6.26.tar.gz
a7 進入解壓後的目錄,執行下面命令(做用:mysql安裝前的屬性設置)
[root@cas src]# cd mysql-5.6.26
[root@cas mysql-5.6.26]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/home/mysql/data -DMYSQL_USER=mysql -DMSLQ_TCP_PORT=3306 -DENABLE_DOWNLOADS=1
a8 編譯
[root@cas mysql-5.6.26]# make
a9 安裝
[root@cas mysql-5.6.26]# make install
a10 清除安裝文件
[root@cas mysql-5.6.26]# make clean
a11 設置目錄權限
[root@cas mysql-5.6.26]# chown -Rf mysql:mysql /usr/local/mysql/
[root@cas mysql-5.6.26]# chown -Rf mysql:mysql /home/mysql
a12 執行初始化腳本
做用 :用於mysql自帶的 數據庫 和 表的初始化 (此時將/home/data目錄 做爲數據存放的目錄)
[root@cas mysql-5.6.26]# cd /usr/local/mysql/
[root@cas mysql]# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/home/mysql/data
a13 修改配置文件權限
[root@cas mysql]# chown -Rf mysql:mysql /usr/local/mysql/my.cnf
注意:
在默認系統中 etc/目錄下也會有一個 my.cnf文件 ,當mysql服務啓動時會默認先讀取/etc/my.cnf 文件,若是/etc/my.cnf 不存在則會到 mysql的安裝目錄下讀取 my.cnf文件 ,所以需將 /etc/my.cnf 文件 改爲其餘名字,不然會干擾到mysql安裝目錄下的 my.cnf文件。
在生產環境下,建議使用/etc/my.cnf文件,此處也是使用my.cnf,操做以下:
aa1 編輯配置文件(將內容清空後添加)
[root@cas mysql]# vim /etc/my.cnf
[client]
port = 3306
socket = /usr/local/mysql/mysql.sock
[mysqld]
character-set-server = utf8
collation-server = utf8_general_ci
skip-external-locking
skip-name-resolve
user = mysql
port = 3306
basedir = /usr/local/mysql
datadir = /home/mysql/data
tmpdir = /home/mysql/temp
# server_id = .....
socket = /usr/local/mysql/mysql.sock
log-error = /home/mysql/logs/mysql_error.log
pid-file = /home/mysql/mysql.pid
open_files_limit = 10240
back_log = 600
max_connections=500
max_connect_errors = 6000
wait_timeout=605800
#open_tables = 600
#table_cache = 650
#opened_tables = 630
max_allowed_packet = 32M
sort_buffer_size = 4M
join_buffer_size = 4M
thread_cache_size = 300
query_cache_type = 1
query_cache_size = 256M
query_cache_limit = 2M
query_cache_min_res_unit = 16k
tmp_table_size = 256M
max_heap_table_size = 256M
key_buffer_size = 256M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
lower_case_table_names=1
default-storage-engine = INNODB
innodb_buffer_pool_size = 512M
innodb_log_buffer_size = 32M
innodb_log_file_size = 128M
innodb_flush_method = O_DIRECT
#####################
thread_concurrency = 32
long_query_time= 2
slow-query-log = on
slow-query-log-file = /home/mysql/logs/mysql-slow.log
[mysqldump]
quick
max_allowed_packet = 32M
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pi
a14 複製啓動腳本目錄
[root@cas mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
a15 啓動服務
[root@cas mysql]# service mysqld start
a16 設置開機自啓動
[root@cas mysql]# chkconfig mysqld on
a17 設置登陸密碼
此處設置密碼爲root
[root@cas mysql]# mysqladmin -u root password 'root'
a18 進入數據庫
[root@cas mysql]# mysql -u root -p
a19 開啓遠程權限
mysql> use mysql;
Database changed
mysql> grant all privileges on *.* to root@'%' identified by "root";
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select host,user,password from user;
+--------------+------+-------------------------------------------+
| host | user | password |
+--------------+------+-------------------------------------------+
| localhost | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
| 192.168.1.1 | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
| % | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
+--------------+------+-------------------------------------------+
3 rows in set (0.00 sec)
B 卸載
b1 查看安裝的mysql
[root@cas ~]# rpm -qa|grep -i mysql
b2 中止mysql服務
[root@cas ~]# service mysqld stop
b3 卸載mysql組件(根據b1查詢的結果)
[root@cas ~]# rpm -ev mysql-***
b4 查找mysql相關文件
[root@cas ~]# whereis mysql
b5 刪除相關文件
[root@cas ~]# rm -rf /usr/local/mysql
b6 刪除mysql用戶及組
[root@cas ~]# userdel mysql
[root@cas ~]# groupdel mysql
b7 刪除配置文件
[root@cas ~]# rm -rf /etc/my.cnf
[root@cas ~]# rm -rf /var/log/mysqld.log
win10
c 安裝
c1 下載安裝包
點擊下圖
c2 解壓下載的安裝包,並將解壓後的文件夾放置想要安裝的目錄,好比D盤
c3 配置環境變量
c4 修改配置文件
拷貝 mysql 目錄中的my-default.ini,重命名爲 my.ini,打開my.ini,修改或添加配置,而後保存
basedir = D:\Program Files\mysql-5.6(mysql所在目錄)
datadir = D:\Program Files\mysql-5.6\data(mysql所在目錄\data)
在配置文件中咱們還看到 port,爲配置 mysql 端口,若是不想用 3306 默認端口,能夠配置想要的端口
c5 用管理員身份運行cmd,進入mysql bin 目錄
c6 初始化: mysqld --initialize-insecure --user=mysql
c7 輸入安裝命令:mysqld install
c7 啓動
輸入:net start myql
c8 進入mysql
首次登陸,密碼爲空
c9 設置密碼
mysql>use mysql; mysql>update user set password=password('your password') where user='root';
mysql>flush privileges;
c10 設置遠程權限
mysql>GRANT ALL PRIVILEGES ON *.* TO 'your username'@'%' IDENTIFIED BY 'your password' WITH GRANT OPTION;
D 卸載
d1 控制面板卸載
控制面板----服務和程序------卸載mysql
d2 刪除文件夾
找到mysql文件夾下的my.ini及其全部組件
d3 刪除註冊表記錄
在控制檯運行regedit.exe
刪除HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Eventlog\Application\MySQL文件夾
刪除HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Services\Eventlog\Application\MySQL文件夾。
刪除HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\MySQL的文件夾。若是沒有能夠不用刪除了。
d4 刪除隱藏文件
刪除C盤下的「C:\ProgramData\MySQL 」因此文件,若是刪除不了則用360粉碎掉便可,該programData文件是隱藏的默認,設置顯示後便可見,或者直接複製上邊的地址到地址欄回車便可進入!刪除後重啓電腦