linux下搭建mysql數據庫
1.下載mysql:
http://dev.mysql.com/downloads/mysql/5.6.html#downloads
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
2.解壓:
#解壓
tar -zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
#復制解壓后的mysql目錄---拷貝到mysql文件夾下
cp -r mysql-5.6.33-linux-glibc2.5-x86_64 /usr/local/mysql
3.加用戶組和用戶
#添加用戶組
groupadd mysql
#添加用戶mysql 到用戶組mysql
useradd -g mysql mysql
4、安裝
cd /usr/local/mysql/
mkdir ./data/mysql
chown -R mysql:mysql ./
./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/mysql
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
cp support-files/my-default.cnf /etc/my.cnf
cd /usr/local/mysql
cd support-files/
ls
cp my-default.cnf /etc/my.cnf
y
vi /etc/init.d/mysqld
service mysqld start --啟動數據庫
chkconfig mysqld on ----開機自啟
cd .. ----切換到根目錄
./bin/mysql -u root -----給root用戶授權
show databases --------顯示datebases
set password=password('123456'); -----設置數據庫密碼為123456
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option; ----給每個用戶每張表授權為密碼為123456的可以登錄
flush privileges; -----刷新權限修改操作,讓命令賦權生效
#修改啟動腳本
vi /etc/init.d/mysqld
#修改項:
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/mysql
#啟動服務
service mysqld start
#測試連接
./mysql/bin/mysql -uroot
#加入環境變量,編輯 /etc/profile,這樣可以在任何地方用mysql命令了
export PATH=$PATH:/usr/local/mysql//bin
source /etc/profile
#啟動mysql
service mysqld start
#關閉mysql
service mysqld stop
#查看運行狀態
service mysqld status
5、錯誤
5.1 sqlyog連接時,報1130錯誤,是由於沒有給遠程連接的用戶權限問題
解決1:更改 ‘mysql’數據庫‘user’表‘host’項,從‘localhost’改成‘%’。
use mysql;
select 'host' from user where user='root';
update user set host = '%' where user ='root';
flush privileges;
解決2:直接授權
GRANT ALL PRIVILEGES ON *.* TO ‘root’@'%’ IDENTIFIED BY ‘youpassword’ WITH GRANT OPTION;
5.2 安裝時的一些錯誤
-bash: ./scripts/mysql_install_db: /usr/bin/perl: bad interpreter: 沒有那個文件或目錄
解決: yum -y install perl perl-devel
Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解決:yum -y install libaio-devel
6、其他
6.1 配置環境變量
vi + /etc/profile
export PATH=....:/usr/local/mysql/bin