1.Centos7安装mysql

rpm安装PHP7相应的yum源

$wget 'https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm'
$sudo rpm -Uvh mysql57-community-release-el7-.noarch.rpm
[root@master2020 mysql]# yum repolist all | grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 141
mysql-connectors-community-source MySQL Connectors Community - disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 105
mysql-tools-community-source MySQL Tools Community - Sourc disabled
mysql-tools-preview/x86_64 MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - Source disabled
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - disabled
mysql56-community/x86_64 MySQL 5.6 Community Server disabled
mysql56-community-source MySQL 5.6 Community Server - disabled
mysql57-community/x86_64 MySQL 5.7 Community Server enabled: 404
mysql57-community-source MySQL 5.7 Community Server - disabled
mysql80-community/x86_64 MySQL 8.0 Community Server disabled
mysql80-community-source MySQL 8.0 Community Server - disabled

如果对别的版本有需求,安装需要的版本就行,只需用yum-config-manager启用或禁用相关的源即可,比如说禁用MySQL5.7启用MySQL5.6

#yum-config=manager 工具安装

yum -y install yum-utils

yum-config-manager --disable mysql57-community

yum-config-manager --enable mysql56-community

安装MySQL Server

yum install mysql-community-server

2.mysql默认端口修改

 vi /etc/my.cnf

3.启动、停止服务

service mysqld start
service mysqld stop

4.查看密码

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

5.初始化安全设置

mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root: ##输入上面的临时root密码
The existing password for the user account root has expired. Please set a new password.
New password: ##设置新密码
Re-enter new password: ##重复密码
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.
Estimated strength of the password:
Change the password for root ? ((Press y|Y for Yes, any other key for No) : #是否更改root密码
... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : ##是否移除匿名用户
... skipping.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y ##是否禁止root远程登录
Success. By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y ##是否删除测试数据库
- Dropping test database...
Success. - Removing privileges on test database...
Success. Reloading the privilege tables will ensure that all changes
made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y ##是否立即刷新权限
Success. All done!

6.登陆

mysql -uroot -p

7.创建数据库、用户

create database if not exists databasename default character set utf8 collate utf8_unicode_ci;
create user username@'%' IDENTIFIED BY '!@#$%^1234';
flush privileges;

8.数据库赋用户权限

grant all privileges on databasename.* to username@localhost identified by '!@#$%^1234';
flush privileges;

9.验证新建用户

mysql -u username -p

10.远程访问数据库

vim /etc/my.cnf    #修改配置文件
[mysqld]
bind-address=0.0.0.0

#端口加入防火墙
grant all privileges on databasename.* to 'username'@'%' identified by '!@#$%^1234';
flush privileges;

11.卸载mysql

#rpm -qa|grep php

# rpm -e php-mysql-5.1.-.el5_5.
# rpm -e php-pdo-5.1.-.el5_5.
# rpm -e php-xml-5.1.-.el5_5.
# rpm -e php-cli-5.1.-.el5_5.
# rpm -e php-gd-5.1.-.el5_5.
# rpm -e php-common-5.1.-.el5_5.
#无法卸载的可以使用
rpm -e php-common-5.1.-.el5_5. --nodeps

最新文章

  1. 【集合框架】JDK1.8源码分析之ArrayList(六)
  2. Java入门第一章
  3. net MVC 重定向总结
  4. docker push 实现过程
  5. Keepass 2.x 之 同步与触发器
  6. Qt绘图之QGraphicsScene QGraphicsView QGraphicsItem详解
  7. Android 有用的快捷键
  8. 测试库的接收到的数据是否完整(jrtplib为列)
  9. Twisted 延迟调用
  10. python maximum recursion depth exceeded 处理办法
  11. rocketmq 集群环境搭建配置
  12. 新Chrome浏览器不支持html5的问题
  13. Memcache在.Net中的使用
  14. mysql查询sending data占用大量时间的问题处理
  15. [svc]linux iptables实战
  16. chorme插件 ,在浏览器上模拟手机,pad 查看网页|前端技术开发必备插件
  17. codeforces 808G Anthem of Berland
  18. 51nod 1623 完美消除(数位DP)
  19. 使用MessageFormat替换字符中的占位符
  20. Thinkphp 导出csv 先存储在服务器,然后输出链接下载

热门文章

  1. C#中struct和class的区别详解 (转载)
  2. Java经典算法50道题
  3. 8核AMD Zen加持:微软Surface这回血拼
  4. 题解:luogu P3909
  5. MySQL复制(一)--复制概述
  6. 修剪草坪 HYSBZ - 2442
  7. hibernate通过数据库表反向生成实体类
  8. Html5 -- 语义标签兼容性处理
  9. CentOS 7 搭建本地YUM仓库,并定期同步阿里云源
  10. 【pwnable.kr】 brainfuck