Mysql數據庫的安裝和配置

1.首先關閉linux的防火牆,查看linux防火牆博客 https://www.cnblogs.com/liuyi-clover/p/9755966.html
2.將下載好的mysql壓縮文件放置在linux的/usr/local文件夾下,解壓該壓縮文件
           tar -zxvf mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz
3.將解壓後的文件重命名爲mysql
           mv mysql-5.6.44-linux-glibc2.12-x86_64 mysqlhtml

4.建立mysql用戶組及用戶
           groupadd mysql
           useradd -r -g mysql mysql
五、進入到mysql目錄,執行添加MySQL配置的操做
           cd mysql
           cp support-files/my-default.cnf /etc/my.cnf
           是否覆蓋?按y 回車
六、編輯/etc/my.cnf文件mysql

           可用工具下載文件到桌面,修改後再上傳到服務器替換linux

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
# server_id = .....
socket = /tmp/mysql.sock
character-set-server = utf8
skip-name-resolve
log-err = /usr/local/mysql/data/error.log
pid-file = /usr/local/mysql/data/mysql.pid

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

 7.在mysql當前目錄下設定目錄的訪問權限(注意後面的小點,表示當前目錄)
          cd /usr/local/mysql
          chown -R mysql .
          chgrp -R mysql .
          scripts/mysql_install_db --user=mysql
          chown -R root .
          chown -R mysql data
八、初始化數據(在mysql/bin或者mysql/scripts下有個 mysql_install_db 可執行文件初始化數據庫),進入該目錄下,執行下面命令   
          cd /usr/local/mysql/scripts
          安裝autoconf庫
          yum -y install autoconf
          初始化mysql
          ./mysql_install_db --verbose --user=root --defaults-file=/etc/my.cnf --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql --pid-file=/usr/local/mysql/data/mysql.pid --tmpdir=/tmp
九、啓動mysql,進入/usr/local/mysql/bin目錄,執行下面命令
          cd /usr/local/mysql/bin
          ./mysqld_safe --defaults-file=/etc/my.cnf --socket=/tmp/mysql.sock --user=root &
          注意,若是光標停留在屏幕上,表示啓動成功,須要咱們先關閉Xshell終端,再從新打開軟件
十、設置開機啓動,新開啓shell中斷後,進入mysql目錄,執行下面命令
         cd /usr/local/mysql
         cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
         cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql
         chmod 700 /etc/init.d/mysql
         chkconfig --add mysqld
         chkconfig --level 2345 mysqld on
         chown mysql:mysql -R /usr/local/mysql/
11.重啓linux,查看mysql狀態
          reboot(可在控制檯手動重啓)
          service mysqld status
          mysql若沒啓動,則啓動mysql
          service mysql start
十二、添加遠程訪問權限
           添加mysql命令
           ln -s /usr/local/mysql/bin/mysql  /usr/bin  (mysql的安裝路徑)
           登陸mysql,執行下面命令
           mysql -u root -h 127.0.0.1 -P3306 -p  (直接回車,可無密碼登錄)
13.修改密碼,執行下面命令
           mysql> select host,user,password from mysql.user;
           mysql> update mysql.user set password=password('12345') where user='root';
           mysql> flush privileges;
           mysql> quit
14.從新啓動mysql,就可使用 新密碼登陸了
           service mysqld status
           mysql若沒啓動,則啓動mysql
           service mysql start
           mysql -u root -h 127.0.0.1 -P3306 -p
           輸入密碼:12345sql

           mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '12345' WITH GRANT OPTION;
           mysql> flush privileges;shell

 1五、鏈接Navicat數據庫

相關文章
相關標籤/搜索