MySQL——安装

centos安装

1. 下载源: http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql80-community-release-el7-2.noarch.rpm

该源目前为8.0版本,如果需要最新请退至根目录找。

wget http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql80-community-release-el7-2.noarch.rpm           #下载源
yum install wget           #如果wget无法使用,请先下载wget

2. 安装源

yum install mysql80-community-release-el7-2.noarch.rpm 

3. 查看是否安装完成

yum repolist enabled|grep "mysql.*-community.*"

查看后会出现,表明为正常安装。

可以修改vi /etc/yum.repos.d/mysql-community.repo源,改变默认安装的mysql版本。

比如要安装8.0版本,将5.7源的enabled=1改成enabled=0。然后再将8.0源的enabled=0改成enabled=1即可。

 4. 安装MySQL

yum install mysql-community-server

5. 启动MySQL服务

systemctl start mysqld
systemctl restart mysqld          #重启MySQL服务

6. 查看MySQL的启动状态

systemctl status mysqld

7.设置开机启动

systemctl enable mysqld
systemctl daemon-reload

8. 查看MySQL默认密码:

mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:

grep 'temporary password' /var/log/mysqld.log

Ubuntu安装:

1. 首先卸载掉原来的mysql

sudo apt-get autoremove --purge mysql-server
sudo apt-get remove mysql-server
sudo apt-get autoremove mysql-server
sudo apt-get remove mysql-common 

2. 安装mysql教程

sudo aptitude search  mysql
sudo apt install  mysql-server

3. 登录

sudo mysql -u root -p    #默认没有密码

4. 设置允许远程访问mysql

vim /etc/mysql/mysql.conf.d/mysqld.cnf    #打开

将bind-address进行备注:

Mysql设置:

MySQL修改密码:

mysql -uroot -p
set password for 'root'@'localhost'=password('Password');  # 5.7 之前版本
alter user 'root'@'localhost' identified by '123456';   #8.0版本

注意:mysql8.0默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误,如下图所示

查看MySQL密码策略:

show variables like '%password%';

mysql密码策略
validate_password_policy:密码策略,默认为MEDIUM策略
validate_password_dictionary_file:密码策略文件,策略为STRONG才需要
validate_password_length:密码最少长度
validate_password_mixed_case_count:大小写字符长度,至少1个
validate_password_number_count :数字至少1个
validate_password_special_char_count:特殊字符至少1个

更详细的MySQL密码信息,请见:https://dev.mysql.com/doc/refman/8.0/en/validate-password-options-variables.html

10. 添加远程用户

默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接,或者添加一个允许远程连接的帐户,为了安全起见,我添加一个新的帐户:

8.0以前的版本:

GRANT ALL PRIVILEGES ON *.* TO 'MySQL'@ '%' IDENTIFIED BY 'MySQL123@#' WITH GRANT OPTION;

8.0以后的版本:

CREATE USER 'zabbix'@'localhost' IDENTIFIED BY '123456';       #创建一个用户
GRANT ALL ON zabbix.* TO 'zabbix'@'localhost' WITH GRANT OPTION;   #授予zabbix的远程登录权限。

%=任意,localhost=本地,192.168.2.% = 某个网段,

查看MySQL下所用户的访问权限:

select * from information_schema.user_privileges;

11. 更改MySQL默认编码格式

show variables like '%character%';    #查看默认编码格式

修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:

[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
default_authentication_plugin=mysql_native_password           #更改默认密码认证方式。

默认配置文件路径:
配置文件:/etc/my.cnf
日志文件:/var/log//var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid

 

posted @ 2019-03-15 10:41  新兵蛋Z  阅读(647)  评论(0编辑  收藏  举报