Mysql基础操作

序言

    随着互联网的发展数据的存储方式也发生了天翻地覆的变化。数据库的应用也将需要一个普及,如你不是专业的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;                      #删除用户
 
 
源码安装过几天总结奉上~
 

 

 

posted @ 2017-07-31 15:27  李雄  阅读(200)  评论(0编辑  收藏  举报