搭建服務器第一步:安裝數據庫html
我這裏選擇的是比較通用的mysql,知足大部分的市場需求了。mysql
首先準備好mysql壓縮包Xshell和Xftp這裏給個地址:https://pan.baidu.com/s/1DHZaroNWV78TYnob5kOTgglinux
一、在上面的連接下載tar包,或者使用wget從官網下載
sql
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gzshell
二、將mysql安裝到/usr/local/mysql下數據庫
# 解壓bootstrap
tar -xvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz服務器
# 移動socket
mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/ide
# 重命名
mv /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql
三、新建data目錄
mkdir /usr/local/mysql/data
四、新建mysql用戶、mysql用戶組
# mysql用戶組
groupadd mysql
# mysql用戶
useradd mysql -g mysql
五、將/usr/local/mysql的全部者及所屬組改成mysql
chown -R mysql.mysql /usr/local/mysql
六、配置
/usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
# 若是出現如下錯誤:
2018-07-14 06:40:32 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize 2018-07-14 06:40:32 [ERROR] Child process: /usr/local/mysql/bin/mysqldterminated prematurely with errno= 32 2018-07-14 06:40:32 [ERROR] Failed to execute /usr/local/mysql/bin/mysqld --bootstrap --datadir=/usr/local/mysql/data --lc-messages-dir=/usr/local/mysql/share --lc-messages=en_US --basedir=/usr/local/mysql -- server log begin -- -- server log end --
# 則使用如下命令:
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize
# 若是出現如下錯誤:
/usr/local/mysql/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
# 則執行如下命令:
yum -y install numactl
# 完成後繼續安裝:
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize
# 編輯/etc/my.cnf
[mysqld] datadir=/usr/local/mysql/data basedir=/usr/local/mysql socket=/tmp/mysql.sock user=mysql port=3306 character-set-server=utf8 # 取消密碼驗證 skip-grant-tables # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # skip-grant-tables [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
七、開啓服務
# 將mysql加入服務
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
# 開機自啓
chkconfig mysql on
# 開啓
service mysql start
八、設置密碼
# 登陸(因爲/etc/my.cnf中設置了取消密碼驗證,因此此處密碼任意)
/usr/local/mysql/bin/mysql -u root -p
# 操做mysql數據庫
>>use mysql;
# 修改密碼
>>update user set authentication_string=password('你的密碼') where user='root';
>>flush privileges;
>>exit;
九、將/etc/my.cnf中的skip-grant-tables刪除
十、登陸再次設置密碼(不知道爲啥若是再也不次設置密碼就操做不了數據庫了)
/usr/local/mysql/bin/mysql -u root -p
>>ALTER USER 'root'@'localhost' IDENTIFIED BY '修改後的密碼';
>>exit;
十一、容許遠程鏈接
/usr/local/mysql/bin/mysql -u root -p
>>use mysql;
>>update user set host='%' where user = 'root';
>>flush privileges;
>>eixt;
十二、添加快捷方式
ln -s /usr/local/mysql/bin/mysql /usr/bin