1. 程式人生 > >linux下載安裝mysal

linux下載安裝mysal

word mys user pass led tor oba har utf8

一.MySQL的版本選擇潛規則:
https://www.mysql.com/

MySQL5.6:
1.選擇GA 6-12個月
2.小版本號為偶數版

MySQL5.7
1.選擇GA 6-12個月
2.小版本號為偶數版
3.MySQL5.7.17以上版本 MGR

二.MySQL源碼安裝
1.解壓
[[email protected] ~]# tar xf mysql-5.6.40.tar.gz
2.進入目錄
[[email protected] ~]# cd mysql-5.6.40
[[email protected] mysql-5.6.40]# ll
3.生成編譯文件

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.40 \

-DMYSQL_DATADIR=/usr/local/mysql-5.6.40/data \
-DMYSQL_UNIX_ADDR=/usr/local/mysql-5.6.40/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_ZLIB=bundled \
-DWITH_SSL=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_DEBUG=0

4.編譯
make

5.安裝
make install


=========================二進制安裝===============================

6.進入mysql程序目錄
[[email protected] ~]# cd /usr/local/mysql-5.6.40/

7.創建mysql系統用戶
[[email protected] mysql-5.6.40]# useradd mysql -s /sbin/nologin -M

8.進入配置文件及腳本目錄
[[email protected] mysql-5.6.40]# cd support-files/

9.拷貝配置文件到etc
[[email protected] support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y

10.拷貝啟動腳本
[[email protected] support-files]# cp mysql.server /etc/init.d/mysqld

11.進入初始化目錄
[[email protected] mysql-5.6.40]# cd /usr/local/mysql-5.6.40/scripts/

12.初始化數據庫
[[email protected] scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql-5.6.40 --datadir=/usr/local/mysql-5.6.40/data

13.做軟連接
[[email protected] scripts]# ln -s /usr/local/mysql-5.6.40 /usr/local/mysql

14.啟動mysql
[[email protected] scripts]# /etc/init.d/mysqld start

Starting MySQL.Logging to ‘/usr/local/mysql/data/db02.err‘.
. SUCCESS!

15.添加環境變量
[[email protected] scripts]# vim /etc/profile
export PATH="/usr/local/mysql/bin:$PATH"

16.加載環境變量
[[email protected] scripts]# source /etc/profile

17.授權
[[email protected] scripts]# chown -R mysql.mysql /usr/local/mysql*

18.連接mysql
[[email protected] scripts]# mysql

19.設置mysql密碼
[[email protected] scripts]# mysqladmin -uroot -p password 123

20.連接mysql
[[email protected] scripts]# mysql -uroot -p123


四.mysql基礎優化:
1.刪除 沒有用的庫
mysql> show databases;
mysql> drop database test;
Query OK, 0 rows affected (0.00 sec)

2.刪除沒有用的用戶
mysql> select user,host from mysql.user;
mysql> drop user [email protected]‘::1‘;
Query OK, 0 rows affected (0.00 sec)
mysql> delete from mysql.user where user=‘root‘ and host=‘db01‘;

linux下載安裝mysal