博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Mysql基础操作
阅读量:6261 次
发布时间:2019-06-22

本文共 3718 字,大约阅读时间需要 12 分钟。

序言

    随着互联网的发展数据的存储方式也发生了天翻地覆的变化。数据库的应用也将需要一个普及,如你不是专业的DB,那么你至少也懂得一些简单的操作才能更好的去管理与认识数据库!

    MySQL (microsoft structure quest language 结构化查询语句)是一种关系型数据库,那么也会有非关系型数据库(redis ...)

 

    1.安装数据库的方式(rpm安装、源码编译安装、yum一键安装)

        #yum -y install mysql mysql-server  安装服务端与客户端 自动解决依赖关系

    2. 启动方式与加入开机自启动项(/etc/init.d/mysqld方式   service方式; chkconfig --add mysqld chkconfig mysql on)

        #/etc/init.d/mysqld  start    通过服务脚本启动

        #service mysqld start    通过service命令启动

        #chkconfig --add mysqld   加入自启动列表

        #chkconfig mysqld on   服务开启开机自启动

    3.给数据库赋予一个安装并强大的密码(/usr/bin/mysqladmin -u root password "你设置的密码")

        #/usr/bin/mysqladmin -u root password "你的密码"    调用mysqladmni 命令设置密码,可以不加前面的路径 如果环境变量ok的话

    4.给新安装的的数据库加固(放止数据丢失,非法登录)

        #安装优化# mysql 安装完成之后需要运行mysql_secure_installation脚本

        #mysql_secure_installation       执行优化脚本,安装后默认会在家目录下面存在

  

[root@localhost ~]# mysql_secure_installation     执行优化脚本

 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL

SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current

password for the root user. If you've just installed MySQL, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

Enter current password for root (enter for none):             #输入原始密码

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL

root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n          #是否修改密码

... 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? [Y/n] y          #是否禁止匿名用户访问

... Success!

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? [Y/n] n          #是否允许root远程登录

... skipping.

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? [Y/n] y      #是否移除test数据库

- 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? [Y/n] y            #是否更新数据库权限表

... Success!

Cleaning up...

 All done! If you've completed all of the above steps, your MySQL

installation should now be secure.

Thanks for using MySQL!

到此数据库优化脚本执行完毕!!!

    5.登录数据库

        mysql -u root -p123456  或者 mysql -u root -p 

    6.手动更新库权限规则(flush privileges;)   切记数据库语句尾部一定要加上“;” 表示执行

        mysql> flush privileges;

        Query OK, 0 rows affected (0.00 sec)

    7.查看数据库版本(select 查询语句)

             

      mysql> select version()\g

      +-----------+
      | version() |
      +-----------+
      | 5.1.73 |
      +-----------+
      1 row in set (0.00 sec)

    8.进入数据库\切换数据库\我所在的数据库

          mysql> use alinx;      #进入alinx数据库

          mysql> select database();  #查看当前所在数据库

    9.创建用户与授权

  

        mysql> CREATE USER username IDENTIFIED BY 'password';                  #创建用户
        mysql>grant all privileges on alinx.* to 'lijie'@localhost identified by 'password';   #授权并改密码     
        mysql>  DROP USER username@localhost;                      #删除用户
 
 
源码安装过几天总结奉上~
 

 

 

转载于:https://www.cnblogs.com/Alinxgood/p/7263316.html

你可能感兴趣的文章
使用windbg抓取崩溃文件和分析的过程
查看>>
ViewHolder模式超简洁写法
查看>>
项目管理学习笔记之三.绩效分析
查看>>
php十行代码将xml转成数组
查看>>
centos 7 执行 groupinstall报错
查看>>
Web开发入门
查看>>
Flex开发小结(1)如何使用AdvancedDataGrid
查看>>
AFNetworking 下载文件断点续传操作
查看>>
Jar mismatch! Fix your dependencies
查看>>
哀悼日, 网页变灰的实现
查看>>
php:检测用户当前浏览器是否为IE浏览器
查看>>
linux命令备份
查看>>
10个你可能不知道的JavaScript小技巧
查看>>
【ASP】文件上传
查看>>
集合类(数据结构图、集合图、集合之间的比较)
查看>>
hibernate _关联级别策略介绍
查看>>
来了!阿里开源分布式事务解决方案 Fescar
查看>>
挑战Kafka!Redis5.0重量级特性Stream尝鲜
查看>>
荣耀畅玩7C挑战红米5 Plus,千元手机档的王者对决
查看>>
聚划算超级聚享日为当代青年人打造理想家居空间
查看>>