前言
首次在Linux系統(tǒng)上使用MySql,筆記還是要記錄一下的球涛。
進(jìn)入正題
本次筆者使用YUM安裝MySql
1劣针、進(jìn)入存放安裝包位置文件夾
cd /usr/src/
2、查看系統(tǒng)中是否已安裝MySql服務(wù)亿扁,有兩種方式
rpm -qa | grep mysql
yum list installed | grep mysql
3捺典、如果已存在,則刪除MySql及其依賴項(xiàng)
yum -y remove mysql-libs.x86_64
4从祝、下載 mysql57-community-release-el7-8.noarch.rpm 的 YUM 源
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
5襟己、安裝 mysql57-community-release-el7-8.noarch.rpm
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
6、安裝 MySql,一路 Y 到底
yum install mysql-server
安裝完畢后牍陌,運(yùn)行mysql擎浴,然后在 /var/log/mysqld.log 文件中會(huì)自動(dòng)生成一個(gè)隨機(jī)的密碼,我們需要先取得這個(gè)隨機(jī)密碼毒涧,以用于登錄 MySQL 服務(wù)端
service mysqld start
grep "password" /var/log/mysqld.log
將會(huì)返回如下內(nèi)容贮预,末尾字符串就是密碼,把它保存下來
A temporary password is generated for root@localhost: 2ru>oFqj+fHw
7、登錄到 MySQL 服務(wù)端并更新用戶 root 的密碼
mysql -u root -p
2ru>oFqj+fHw
登陸后更改密碼(密碼使用了強(qiáng)度驗(yàn)證仿吞,所以需要有一定強(qiáng)度的密碼)
ALTER USER 'root'@'localhost' identified by 'Root123456..(新密碼)';
flush privileges;
設(shè)置用戶 root 可以在任意 IP 下被訪問
grant all privileges on *.* to root@"%" identified by 'Root123456..';
設(shè)置用戶 root 可以在本地被訪問
grant all privileges on *.* to root@"localhost" identified by 'Root123456..';
然后刷新權(quán)限后生效
flush privileges;
這樣環(huán)境就搭建完成了滑频。
注意:如果用遠(yuǎn)程工具還是連接不上,試試用 iptables -F 命令來清除防火墻中鏈中的規(guī)則
8.修改配置表
打開配置表唤冈,文件路徑:
/etc/my.cnf
設(shè)置 MySQL 的字符集為 UTF-8
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# 設(shè)置 MySQL 的字符集為 UTF-8
[client]
default-character-set=utf8
[mysqld]
# 設(shè)置 MySQL 的字符集為 UTF-8
character_set_server=utf8
#
# 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
#
# 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
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
重啟MySql后登陸峡迷,查看字符集
show variables like '%character%';
9.MySQL 采用的 TCP/IP 協(xié)議傳輸數(shù)據(jù),默認(rèn)端口號(hào)為 3306你虹,我們可以通過如下命令查看
netstat -anp
常用Sql命令
--執(zhí)行 sql 腳本
\. <sql文件絕對(duì)路徑>
--查看MySql數(shù)據(jù)庫物理文件存放位置
mysql> show global variables like "%datadir%";
常用的相關(guān)管理Shell命令
service mysqld start; 啟動(dòng)
service mysqld stop; 停止
service mysqld restart; 重啟
service mysqld status; 查看狀態(tài)
systemctl start mysqld
service mysqld stop
service mysqld restart
systemctl status mysqld