公司內網沒有外網,需要安裝mysql,因此只好下載mysql包進行安裝
下載安裝
下載地址:https://downloads.mysql.com/archives/community/
選擇相應的版本現在即可
RPM Bundle
這個應該是 rpm的安裝包
下載後直接解壓,然後直接執行命令安裝即可
rpm -ivh mysql* 或者 rpm -y localinstall mysql*
也可以選擇源碼安裝
爲了省事,我直接選擇了 RPM Bundle
下載後解壓,運行即可
如果安裝報錯,可用查看下是否有系統自帶的低版本的mysql
rpm -qa |grep mariadb
rpm -qa |grep mysql
如果有的話,直接卸載即可
rpm -e mariadb-devel-5.5-el7.x86_64(查詢出來的安裝包名)
安裝後的配置操作
A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.
You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.
Also, the account for the anonymous user has been removed.
In addition, you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test database.
This is strongly recommended for production servers.
See the manual for more instructions.
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
上面的意思大概就是說:
隨機密碼設置給了root用戶,你要找的隨機密碼在/root/.mysql_secret文件中
使用隨機密碼登錄後要修改密碼才能正常操作吧
默認的配置文件創建在了/usr/my.cnf
到這裏,MySQL服務器已經安裝完成了。
然後啓動數據庫
systemctl restart mysql.service
查看初始密碼
cat /root/.mysql_secret
在文本的local time
後面的字符
第一次登錄需要設置設置密碼
mysql -u root -p
輸入上面的默認密碼
set password=password('123456'); # 修改密碼爲123456
或者這樣
set password for 'root'@'localhost'=password('456789');
設置允許遠程訪問,不設置的話,只能在本機訪問
use mysql
grant all privileges on *.* to 'root'@'%' identified by '123456';
flush privileges;
創建數據庫
show databases;
CREATE DATABASE micro;
set character_set_database='utf8';
查看數據庫編碼
show create database micro;
修改數據庫編碼爲utf-8:
alter database micro default character set utf8 collate utf8_general_ci;
數據庫編碼的一些知識
鏈接接:https://blog.csdn.net/yuezhuo_752/article/details/84037269
開放防火牆
firewall-cmd --zone=public --add-port=3306/tcp --permanent
systemctl restart firewalld.service
這樣基本上就可用安裝完畢了。