安裝
wget
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
yum install mysql-server
systemctl start mysqld
找初始密碼:
# grep "temporary password" /var/log/mysqld.log
2020-07-01t01:37:50.408894z 1 [note] a temporary password is generated for root@localhost: (alter user 'root'@'localhost' identified by '_shanghai#31';
query ok, 0 rows affected (0.01 sec)
開啟遠端連線:
show databases;
use mysql;
show tables;
update user set host='%' where user='root';
grant all privileges on *.* to root@"192.168.%" identified by "_shanghai#31";
flush privileges;
配置預設編碼為utf8
vi /etc/my.cnf
# 新增 [mysqld]
character_set_server=utf8
init_connect='set names utf8'
更改mysql安裝目錄:
先建立目錄
[root@dev-base1 /data]
# cd /data
# mkdir mysqldata
# chmod 777 /data/mysqldata
停止資料庫
# systemctl stop mysqld
複製資料目錄 & 備份原有資料目錄
# cp -r /var/lib/mysql /data/mysqldata
# mv /var/lib/mysql /var/lib/mysql_bak
# chown -r mysql:mysql /data/mysqldata
修改配置檔案:
# vim /etc/my.cnf
新增配置:
datadir=/data/mysqldata/mysql
socket=/data/mysqldata/mysql.sock
log-error=/data/mysqldata/mysql/mysqld.log
啟動資料庫&設定開機自啟
# systemctl restart mysqld
# systemctl enable mysqld
檢視啟動程序:
[root@dev-base1 /data/mysqldata]
# ps -ef |grep mysql
mysql 1183 1 1 10:06 ? 00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root 1213 62664 0 10:07 pts/0 00:00:00 grep --color=auto mysql
登入測試:
[root@dev-base1 /data/mysqldata]
# mysql -u root -p
enter password:
error 2002 (hy000): can't connect to local mysql server through socket '/var/lib/mysql/mysql.sock' (2)
解決mysql.sock問題:
[root@dev-base1 /data/mysqldata]
# mkdir -p /var/lib/mysql
[root@dev-base1 /data/mysqldata]
# ln -s /data/mysqldata/mysql.sock /var/lib/mysql/mysql.sock
[root@dev-base1 /data/mysqldata]
# mysql -u root -p
enter password:
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is 4
server version: 5.7.30 mysql community server (gpl)
oracle is a registered trademark of oracle corporation and/or its
affiliates. other names may be trademarks of their respective
owners.
type 'help;' or '\h' for help. type '\c' to clear the current input statement.
mysql>
linux 環境下安裝MySQL5 7(yum)
安裝環境 centos7 64位,mysql5.7 1.配置yum源 複製鏈結,然後wget wget安裝mysql源 yum localinstall mysql57 community release el7 8.noarch.rpm檢查mysql源是否安裝成功 安裝mysql yum inst...
linux伺服器安裝mysql5 7 yum安裝
注意 以阿里雲伺服器ecs為例,安裝mysql。檢視mysql與linux版本對應的資料 檢視當前linux版本命令 uname a 或 cat proc version wget3 sudo yum localinstall mysql57 community release el7 11.noa...
Mysql5 7安裝之yum安裝方式
wget 注意 若wget命令用不了,wget command not found的解決辦法 yum localinstall mysql57 community release el7 8.noarch.rpmyum repolist enabled grep mysql.community.這一...