官網:https://dev.mysql.com/downloads/repo/yum/
如圖,目前的版本已經到8了,咱們先把yum源下載下來,而且導入到linux服務器目錄下。node
而後咱們執行rpm -ivh mysql80-community-release-el7-2.noarch.rpm
mysql
固然還有一種方式,就是咱們直接在線下載:直接安裝本身須要的版本linux
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum repository 安裝mysql的方式咱們是能夠選擇本身的軟件源的。若是不修改就跳過sql
[mysql-connectors-community] name=MySQL Connectors Community baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [mysql-tools-community] name=MySQL Tools Community baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql # Enable to use MySQL 5.5 [mysql55-community] name=MySQL 5.5 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql # Enable to use MySQL 5.6 [mysql56-community] name=MySQL 5.6 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql # Note: MySQL 5.7 is currently in development. For use at your own risk. # Please read with sub pages: https://dev.mysql.com/doc/relnotes/mysql/5.7/en/ [mysql57-community-dmr] name=MySQL 5.7 Community Server Development Milestone Release baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
上面我是本身修改了,改成5.7. 主要修改這個enabled就能夠。用哪一個版本,就把那個版本下改成enabled=1,其餘的所有enabled=0; 固然也能夠複製粘貼一個新的版本。數據庫
查看不一樣版本默認啓用狀況:安全
能夠看到 enabled 的狀況服務器
[root@iZszxghs0ozok0Z yum.repos.d]# yum repolist all |grep mysql !mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 95 mysql-connectors-community-source MySQL Connectors Community - disabled !mysql-tools-community/x86_64 MySQL Tools Community enabled: 84 mysql-tools-community-source MySQL Tools Community - Sourc disabled mysql55-community/x86_64 MySQL 5.5 Community Server disabled mysql55-community-source MySQL 5.5 Community Server - disabled !mysql56-community/x86_64 MySQL 5.6 Community Server enabled: 446 mysql56-community-source MySQL 5.6 Community Server - disabled mysql57-community-dmr/x86_64 MySQL 5.7 Community Server De disabled mysql57-community-dmr-source MySQL 5.7 Community Server De disabled
修改完查看默認啓用的最終版本狀況:ide
[root@iZszxghs0ozok0Z yum.repos.d]# yum repolist enabled | grep mysql !mysql-connectors-community/x86_64 MySQL Connectors Community 95 !mysql-tools-community/x86_64 MySQL Tools Community 84 !mysql56-community/x86_64 MySQL 5.6 Community Server 446
能夠看到,咱們默認開啓了 5.6 版本,post
總結下這幾個命令google
yum repolist all |grep mysql yum repolist enabled | grep mysql
yum list installed | grep mysql
或者
rpm -qa | grep -i mysql
查看是否已經有安裝的mysql,若是有,須要手動卸載掉。
rpm -e --nodeps 軟件名
或者yum -y remove 軟件名
安裝以前若是沒有更新yum 的最好更新下
更新:yum update
安裝:yum install mysql-community-server
權限設置:chown mysql:mysql -R /var/lib/mysql
初始化mysql:mysqld --initialize
啓動mysql: systemctl start mysqld
查看mysql 運行狀態:
systemctl status mysqld
看到active (running) 表示正常。
[root@iZszxghs0ozok0Z yum.repos.d]# systemctl status mysqld ● mysqld.service - MySQL Community Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2019-03-23 01:40:37 CST; 3 days ago Process: 9115 ExecStartPost=/usr/bin/mysql-systemd-start post (code=exited, status=0/SUCCESS) Process: 9055 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS) Main PID: 9114 (mysqld_safe) CGroup: /system.slice/mysqld.service ├─9114 /bin/sh /usr/bin/mysqld_safe --basedir=/usr └─9280 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/l...
mysqladmin --version
[root@iZszxghs0ozok0Z yum.repos.d]# mysqladmin --version mysqladmin Ver 8.42 Distrib 5.6.43, for Linux on x86_64
執行這條命令,若是未輸出任何信息,說明未安裝成功。
直接在命令行輸入mysql回車,發現已經進入了mysql服務,沒有密碼。
mysql安裝完成後默認是沒有密碼的,固然,用rpm安裝有個初始密碼,這個本章不考慮。這裏咱們須要建立用戶的密碼。
mysqladmin -u root password "123456"
這裏我將用戶root ,設置密碼爲123456。
mysql -u root -p 123456
登陸mysql,進行操做。
咱們默認是用的root權限,若是不想直接用root這個帳號遠程操做數據庫,須要咱們手動建立一個帳號。
(1)登陸mysql ,這裏咱們已經登陸了
沒密碼用mysql,有密碼用 mysql -u root -p
(2)建立帳號admin,並將密碼設爲123456,設置訪問權限。
grant all on *.* to admin@'%' identified by "123456";
%表明任何客戶機均可以鏈接,localhost表明只能夠本機鏈接
固然能夠分步,好比咱們
grant all on *.* to admin@'localhost' identified by '123456';
這裏是只添加了帳號,外部仍是不能訪問,咱們能夠修改權限。
update user set host = '%' where user = 'admin';
以上兩種方式都是能夠的,這裏只是說明,避免誤解。
(3)查看下是否添加或者修改爲功
use mysql; select user,host from user where user="admin"
這時候應該會輸出,
mysql> select user,host from user where user='admin'; +-------+------+ | user | host | +-------+------+ | admin | % | +-------+------+ 1 row in set (0.00 sec)
(4) 更新數據庫
命令:flush privileges;
因爲咱們的服務器在遠程,好比阿里雲,咱們設置遠程登陸,就不用像虛擬機那樣了。咱們只須要開放阿里雲權限策略組的3306 端口。
這個這裏就不貼圖了,登陸本身的阿里雲服務器,進入安全組——添加規則——添加mysql協議,默認爲3306,受權對象設爲 0.0.0.0/0 就能夠了。而後用sqlyog或者Navicat試一下。
若是還不行:多半是防火牆的問題,請自行百度+google 不少哈哈哈哈哈哈。