Centos下使用yum安裝mysql

安裝mysql

# 下載並安裝mysql官方Yum Repository
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm

#直接安裝mysql
yum -y install mysql-community-server

啓動mysql

service mysqld start

查看mysql狀態

service mysqld status
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2019-11-09 10:22:33 CST; 5s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 8085 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 8031 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 8089 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─8089 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

running狀態表示mysql正在運行中,可是要鏈接使用mysql,還得找到mysql的用戶名和密碼html

查看默認密碼

#命令
grep "password" /var/log/mysqld.log
#結果
[Note] A temporary password is generated for root@localhost: hOa9fsoqgS=6

默認密碼爲:hOa9fsoqgS=6mysql

登錄mysql

# 命令
mysql -uroot -p  #回車後輸入上述密碼

修改密碼

MySQL默認必須修改密碼以後才能操做數據庫,所以必須修改密碼sql

ALTER USER 'root'@'localhost' IDENTIFIED BY '9^B6SuztL3j2%P$s';

固然修改密碼的過程當中,可能會出現如下提示shell

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

緣由是你的密碼不符合mysql的內置規範,內置規範這裏不作多講,儘可能把密碼設置的複雜就能夠了數據庫

可視化工具登錄受權

若是要使用外部工具鏈接mysql的話,須要額外受權ide

grant all on *.* to root@'%' identified by '數據庫密碼';

設置字符集

設置mysql字符集爲UTF-8,不然中文會亂碼。退出mysql,使用下面命令編輯mysql配置文件工具

vi /etc/my.cnf
相關文章
相關標籤/搜索