Linux系统安装MySQL
1.添加rpm源,选择较新的源命令
wget -i http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
yum -y install mysql57-community-release-el7-7.noarch.rpm
yum repolist enabled | grep mysql
报错1:
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
You need to be root to perform this command.
解决方案:输入su 回车输入root密码
报错2提示su: Authentication failure,
解决方案:输入sudo passwd root,输入devops账号的密码,修改一次密码。下次再su的时候只要输入密码就可以成功登录了。
报错3:devops is not in the sudoers file This incident will be reported.
解决方案:编辑sudoers文件
vi /etc/sudoers
找到这行 root ALL=(ALL) ALL,在下面添加 devops ALL=(ALL) ALL
重新尝试解决方案1和解决方案2
2.安装mysql 服务器
yum install mysql-community-server
这步可能很慢,有的镜像比较慢,可能超过5小时。可以取消,重新来一遍。
3.启动mysql
service mysqld start
4.设置开机自启动
查看mysql是否自启动
chkconfig --list | grep mysqld
chkconfig mysqld on
设置开机自启动
systemctl enable mysqld.service
5.设置密码
mysqladmin -uroot -p mysql
Enterpassword:xxxxxx
error: 'Access denied for user 'root'@'localhost' (using password: YES)'
解决如下:
1.停止mysql服务
systemctl stop mysqld.service
2.修改配置文件无密码登录
vi /etc/my.cnf
在最后加上
skip-grant-tables
保存 (:wq)
3.启动mysql
systemctl start mysqld.service
4.登录mysql
mysql -u root
注意这里不要加-p
5.修改密码,mysql5.7用此语法
use mysql;
update mysql.user set authentication_string=password('123456') where user='root' ;
密码简单,会引发报错:1819 Your password does not satisfy the current policy requirements
update mysql.user set authentication_string=password('***@***') where user='root' ;
修改密码,可使用大写字母、小写字母、特殊字符、数字的组合。执行如下命令:
update mysql.user set authentication_string=password('Aabcd@#1234') where user='root';
flush privileges;
6.回到第2步把刚加的那句skip-grant-tables 删掉
保存,重启mysql就可以了
systemctl stop mysqld.service
systemctl start mysqld.service
6.登录mysql
mysql -u root -p
Enterpassword:xxxxxx
7.设置密码不过期
mysql> use jira
报错:ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
密码过期了,修改密码,设置永不过这期。
执行以下命令:
SET PASSWORD = PASSWORD('Aabcd@#1234');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
flush privileges;
8.添加用户
CREATE USER 'king@localhost' IDENTIFIED BY 'xx@xxxxxx'
创建远程连接用户
GRANT ALL PRIVILEGES ON *.* TO 'king'@'%' IDENTIFIED BY 'xx@xxxxxx' WITH GRANT OPTION;
(%表示所有的电脑都可以连接,也可以设置某个ip地址运行连接)。
9.设置时区
set global time_zone = ‘+8:00’;#修改MySQL全局时区为背景时间
set time_zone = ‘+8:00’; #修改当前会话时区
flush privileges; #立即生效