1:查看 linux下是否有老版本的mysql(有刪除)html
查找old mysql:rpm -qa | grep mysqlnode
卸載:卸載命令:rpm –ev {包名}——:rpm -ev mysql-community-common-5.7.23-1.el7.x86_64mysql
查找老版本mysql相關的安裝目錄命令:find / -name mysqllinux
若查找到相關目錄使用命令:rm –rf {目錄名}:刪除目錄sql
2:查看 linux 下是否安裝 mariadb 數據庫(有的話須要刪除,由於有衝突)數據庫
檢查是否安裝了 mariadb: rpm -qamariadb | grepvim
刪除mariadb:rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64安全
3:建立mysql存放目錄(/root/software)socket
建立文件夾:mkdir /root/softwareide
解壓到當前文件夾,並把解壓後文件移動到指定文件夾並修文件夾名稱:
解壓:tar -xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
移動並修更名字:mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql
4:建立主目錄(data:存儲目錄)
建立主目錄:mkdir /usr/local/mysql/data
5:主目錄權限處理(查看是否有就得用戶,有刪除並新建用戶)
查看組和用戶狀況:cat /etc/group | grep mysql
查看組和用戶狀況:cat /etc/passwd |grep mysql
若存在,則刪除原mysql用戶:userdel -r mysql,會刪除其對應的組和用戶並在次查看。
建立mysql組:groupadd mysql
建立mysql用戶:useradd -r -g mysql mysql
修改目錄擁有者:chown -R mysql:mysql /usr/local/mysql
6:建立配置文件及相關目錄(若是在這個路徑下已經存在的話就不用建立了)
建立配置文件:vim /etc/my.cnf
文件模板:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/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 = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
# 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
修改配置文件內容:注意要在模板的 [mysqld] 下面去修改(basedir:mysql安裝路徑,datadir:數據存儲目錄)
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
socket=/tmp/mysql.sock
pid-file=/tmp/mysqld/mysqld.pid
character-set-server = utf8
log-error=/var/log/mysqld.log
保存退出:wq!
建立文件/tmp/mysql.sock:設置用戶組及用戶,受權
cd /tmp
touch mysql.sock
chown mysql:mysql mysql.sock
chmod 755 mysql.sock
建立文件/tmp/mysqld/mysqld.pid
mkdir mysqld
cd mysqld
touch mysqld.pid
cd ..
chown -R mysql:mysql mysqld
cd mysqld
chmod 755 mysqld.pid
建立文件/var/log/mysqld.log:
touch /var/log/mysqld.log
chown -R mysql:mysql /var/log
cd /var/log
chmod 755 mysqld.log
7:安裝和初始化數據庫
進入初始化目錄:cd /usr/local/mysql/bin/
初始化數據庫:./mysqld --initialize --user=mysql --basedir=/usr/local/mysql--datadir=/usr/local/mysql/data
若是報錯:(./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory)
須要安裝命令:yum -y install numactl
以後在執行初始化數據庫:./mysqld --initialize --user=mysql --basedir=/usr/local/mysql--datadir=/usr/local/mysql/data
8:安全啓動:
./mysqld_safe --user=mysql &
以後回車進入到bin目錄
查看是否成功:ps -ef | grep mysql
默認密碼在mysqld.log日誌裏, 找到後保存到安全的地方:cat /var/log/mysqld.log
其中root@localhost: 後面的就是默認密碼,後面登陸用(D;J.ogLj8ETr)
進入bin目錄:
cd /usr/local/mysql/bin/
登陸mysql:
./mysql -u root -p
可是,若輸入相關命令,則會提示你修改用戶密碼(注意後面必定要加;)。
show databases;
密碼修改成 aaa
mysql> set password=password("aaa");
9:設置遠程登陸權限(在mysql裏面設置)
mysql>grant all privileges on *.* to 'root'@'%' identified by 'aaa';
刷新登陸權限:
mysql> flush privileges;
退出quit 或者 exit
mysql> quit;
10:開機服務啓動設置:
把support-files/mysql.server 拷貝爲/etc/init.d/mysql:
命令:cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
查看是否成功:(名字爲mysql)
cd /etc/init.d/
ll
查看mysql服務是否在服務配置中
chkconfig --list mysql
若沒有,則把mysql註冊爲開機啓動的服務,而後在進行查看
chkconfig --add mysql
chkconfig --list mysql
啓動 或 中止
service mysql start
service mysql stop
11:建立快捷方式:
服務啓動後,直接運行mysql -u root -p便可登陸,不須要進入到對應的目錄。
ln -s /usr/local/mysql/bin/mysql /usr/bin
12:使用Navicat 鏈接數據庫時會出現(2003)
說明你的防火牆沒有關。
解決方案:
//臨時關閉 systemctl stop firewalld
//禁止開機啓動
systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.