linux版本:html
一、下載安裝包「mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz」 mysql
# 安裝依賴 yum -y install perl perl-devel autoconf libaio
二、把下載的安裝包移動到/usr/local/下。linux
三、解壓sql
tar zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
四、複製解壓後的mysql目錄到系統的本地軟件目錄數據庫
cp mysql-5.6.33-linux-glibc2.5-x86_64 /usr/local/mysql -r
五、添加系統mysql組和mysql用戶服務器
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
注意:Because the user is required only for ownership purposes, not login purposes, the useradd command uses the -r and -s /bin/false options to create a user that does not have login permissions to your server host. Omit these options if your useradd does not support them.
六、進入安裝mysql軟件目錄,修改目錄擁有者爲mysql用戶ide
cd mysql/
chown -R mysql:mysql ./
七、安裝數據庫,此處可能出現錯誤。ui
./scripts/mysql_install_db --user=mysql
問題1:FATAL ERROR: please install the following Perl modules before executing scripts/mysql_install_db:
Data::Dumper
#解決方法:
yum install -y perl-Data-Dumper
問題2:Installing MySQL system tables.../usr/local/mysql/bin/mysqld: error while loading shared 緣由是:缺乏libaio庫文件
#解決方法:
yum install libaio* -y
八、修改當前目錄擁有者爲root用戶spa
chown -R root:root ./
九、修改當前data目錄擁有者爲mysql用戶.net
chown -R mysql:mysql data
============== 到此數據庫安裝完畢 =============
十、添加mysql服務開機自啓動
添加開機啓動,把啓動腳本放到開機初始化目錄。
cp support-files/mysql.server /etc/init.d/mysql # 賦予可執行權限 chmod +x /etc/init.d/mysql # 添加服務 chkconfig --add mysql # 顯示服務列表 chkconfig --list
若是看到mysql的服務,而且3,4,5都是on的話則成功,若是是off,則執行
chkconfig --level 345 mysql on
十一、啓動mysql服務
#建立缺乏的文件夾
mkdir /var/log/mariadb
service mysql start
正常提示信息:Starting MySQL. SUCCESS!
十二、把mysql客戶端放到默認路徑
ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
經過使用 mysql -uroot -p 鏈接數據庫(默認數據庫的root用戶沒有密碼,這個須要設置一個密碼)。
----------------------建立本身的用戶------------------------------------
添加新用戶
容許本地 IP 訪問 localhost, 127.0.0.1
create user 'test'@'localhost' identified by '123456';
容許外網 IP 訪問
create user 'test'@'%' identified by '123456';
刷新受權
flush privileges;
爲用戶建立數據庫
create database test DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
爲新用戶分配權限
授予用戶經過外網IP對於該數據庫的所有權限
grant all privileges on `testdb`.* to 'test'@'%' identified by '123456';
授予用戶在本地服務器對該數據庫的所有權限
grant all privileges on `testdb`.* to 'test'@'localhost' identified by '123456';
刷新權限
flush privileges;
退出 root 從新登陸
exit
用新賬號 test 從新登陸,因爲使用的是 % 任意IP鏈接,因此須要指定外部訪問IP
mysql -u test -h 115.28.203.224 -p
------------------在mysql -uroot -p下建立user的另外一方法-----------------------------------------
GRANT USAGE ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'admin' WITH GRANT OPTION;
------------------出現中文亂碼問題的解決-----------------------------------------
https://blog.csdn.net/sayoko06/article/details/76679380