centOS Linux下用yum安装mysql
 
   第一篇:安装和配置MySQL
  第一步:安装MySQL
 
[root@192 local]# yum -y install mysql-server ← 安装MySQL
 
[root@192 local]# yum -y install php-mysql    ← 安装php-mysql
 
  第二步:配置MySQL
 
[root@192 local] #vim /etc/my.cnf             ← 编辑MySQL的配置文件
 
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1  ← 找到这一行,在这一行的下面添加新的规则,让MySQL的默认编码为UTF-8
default-character-set = utf8  ← 添加这一行
 
然后在配置文件的文尾填加如下语句:
 
[mysql]
default-character-set = utf8
 
 
 
       第二篇:启动MySQL和初始环境设定
 
 
  第一步:启动MySQL服务
 
[root@192 local]#chkconfig mysqld on ← 设置MySQL服务随系统启动自启动
 
[root@192 local]#chkconfig --list mysqld ← 确认MySQL自启动
mysqld          0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭
 
                                              ← 如果2--5为启用(或on)的状态就OK
 
[root@192 local]#/etc/rc.d/init.d/mysqld start  ← 启动MySQL服务
 
初始化 MySQL 数据库: Installing MySQL system tables...
OK
Filling help tables...
OK
 
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
 
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h 192.168.0.1 password 'new-password'
 
Alternatively you can run:
/usr/bin/mysql_secure_installation
 
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
 
See the manual for more instructions.
 
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
 
Please report any problems with the /usr/bin/mysqlbug script!
 
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses athttp://shop.mysql.com
                                                           [确定]
启动 mysqld:                                              [确定]
 
 
 
 
  第二步:MySQL初始环境设定
 
  [1]  为MySQL的root用户设置密码
 
MySQL在刚刚被安装的时候,它的root用户是没有被设置密码的。首先来设置MySQL的root密码。
 
[root@192 local]#mysql -u root  ← 在没设置密码之时,用root用户登录MySQL服务器
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.95 Source distribution
 
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
 
 
mysql> select user,host,password from mysql.user;  ← 查看用户信息
mysql> select user,host,password from mysql.user;
+------+-------------+----------+
| user | host        | password |
+------+-------------+----------+
| root | localhost   |          | 
| root | 192.168.0.1 |          | 
| root | 127.0.0.1   |          | 
|      | localhost   |          | 
|      | 192.168.0.1 |          | 
+------+-------------+----------+
5 rows in set (0.03 sec)
 
mysql> set password forroot@localhost=password ('在这里填入root密码');  ← 设置root密码
 
譬如,在我的系统中,我是如下设置:
 
mysql> set password for root@localhost=password ('wangyun');
 
Query OK, 0 rows affected (0.01 sec)
 
mysql> set password for root@192.168.0.1=password ('wangyun');
Query OK, 0 rows affected (0.01 sec)
 
mysql> set password for root@127.0.0.1=password ('wangyun');
Query OK, 0 rows affected (0.01 sec)
 
 
 
mysql> select user,host,password from mysql.user;  ← 查看用户信息
 
+------+-------------+------------------+
| user | host        | password         |
+------+-------------+------------------+
| root | localhost   | 5f2dfe4b07af795b | 
| root | 192.168.0.1 | 5f2dfe4b07af795b | 
| root | 127.0.0.1   | 5f2dfe4b07af795b | 
|      | localhost   |                  | 
|      | 192.168.0.1 |                  | 
+------+-------------+------------------+
5 rows in set (0.01 sec)
 
mysql> exit  ← 退出MySQL服务器
Bye
 
 
 
  [2] 测试设置的root密码是否生效
 
 
 
[root@192 local]# mysql -u root      ← 通过空密码用root登录
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
                                     ← 出现此错误信息说明密码设置成功
 
[root@192 local]# mysql -u root-p    ← 通过密码用root登录
Enter password: ← 在这里输入密码
 
 
Welcome to the MySQL monitor.  Commands end with ; or \g.  ← 确认用密码能够成功登录
Your MySQL connection id is 5
Server version: 5.0.95 Source distribution
 
...  ...
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
[root@192 local]#mysql -u root -h 127.0.0.1 -p ← 通过密码用root登录
Enter password:   ← 在这里输入密码
Welcome to the MySQL monitor.  Commands end with ; or \g.← 确认用密码能够成功登录
Your MySQL connection id is 13
Server version: 5.0.95 Source distribution
 
......
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> exit  ← 退出MySQL服务器
Bye
 
 
 
   [3] 删除匿名用户
 
 
 
在MySQL刚刚被安装后,存在用户名、密码为空的用户。这使得数据库服务器有无需密码被登录的可能性。为消除隐患,将匿名用户删除。
 
 
 
[root@192 local]# mysql -u root -p; ← 通过密码用root登录
Enter password:    ← 在这里输入密码
 
 
 
mysql> select user,host from mysql.user;
+------+-------------+
| user | host        |
+------+-------------+
| root | 127.0.0.1   | 
|      | 192.168.0.1 | 
| root | 192.168.0.1 | 
|      | localhost   | 
| root | localhost   | 
+------+-------------+
5 rows in set (0.03 sec)
 
 
 
mysql> delete from mysql.user where user=''; ← 删除匿名用户
 
Query OK, 2 rows affected (0.04 sec)
 
 
 
mysql> select user,host from mysql.user;  ← 查看用户信息
 
+------+-------------+
| user | host        |
+------+-------------+
| root | 127.0.0.1   | 
| root | 192.168.0.1 | 
| root | localhost   | 
+------+-------------+
3 rows in set (0.00 sec)
 
 
 
mysql> flush privileges;  ← 刷新,使以上操作生效
 
mysql> exit;   ←退出MySQL服务器
Bye
 
 
 
第三篇:测试
经过第一篇和第二篇这二部分的设置,MySQL就可以正常试用。
 
好了,第三篇的内容都不是必须的了!
我们来测试MySQL,让我们学习或复习常用的SQL语句。
 
[root@192 local]#mysql -u centospub-p;  ← 通过密码用root登录
Enter password: ← 在这里输入密码
 
mysql> grant all privileges on test.* to centospub@localhost  identified by '在这里定义密码';
 
                                ← 建立对test数据库有完全操作,权限的名为centospub的用户
 
譬如,在我的系统中,设置如下:
 
mysql>grant all privileges on test.* to centospub@localhost  identified by'wangyun';
                       
Query OK, 0 rows affected (0.03 sec)
 
 
 
mysql> select user from mysql.user where user='centospub';← 确认centospub用户的存在与否
 
|+----------+
| user      |
+-----------+
| centospub | 
+-----------+
1 row in set (0.02 sec)
 
 
mysql> exit;
Bye
[root@192 local]# mysql -u centospub -p; ← 用新建立的centospub用户登录MySQL服务器
Enter password:   ← 在这里输入密码
 
 
 
mysql>create database test;  ← 建立名为test的数据库
mysql> show databases;       ← 查看系统已存在的数据库
 
+--------------------+
| Database           |
+--------------------+
| information_schema | 
| test               | 
+--------------------+
2 rows in set (0.01 sec)
 
 
 
mysql> use test  ← 连接到数据库
Database changed
 
mysql> create table test     
    -> (
    -> num int ,      ← 在数据库中建立表
    -> name varchar(50)
    -> );
Query OK, 0 rows affected (0.14 sec)
 
 
mysql> show tables;  ← 查看数据库中已存在的表
+----------------+
| Tables_in_test |
+----------------+
| test           | 
+----------------+
1 row in set (0.02 sec)
 
mysql> insert into test values(1,'Hello World!');  ← 插入一个值到表中
Query OK, 1 row affected (0.02 sec)
 
mysql> select * from test;  ← 查看数据库中的表的信息
+------+-------------------+
| num | name      |
+------+-------------------+
| 1   | Hello World!  |
+------+-------------------+
1 row in set (0.00 sec)
 
 
 
 
mysql>  update test set name='Hello Everyone!'; ← 更新表的信息,赋予新的值
 
Query OK, 1 row affected (0.14 sec)
Rows matched: 1  Changed: 1  Warnings: 0
 
mysql>  select *from test;  ← 查看数据库中的表的信息
 
+------+-----------------+
| num  | name            |
+------+-----------------+    ← 确认被更新到新的值
|    1 | Hello Everyone! |   
+------+-----------------+
1 row in set (0.01 sec)
 
mysql> delete from test where num=1; ← 删除表内的值
Query OK, 1 row affected (0.01 sec)
 
mysql> select * from test;  ← 确认删除结果
Empty set (0.01 sec)
 
mysql> drop table test;     ← 删除表
Query OK, 0 rows affected (0.01 sec)
 
mysql> show tables;         ← 查看表信息
Empty set (0.00 sec)        ← 确认表已被删除
 
mysql> drop database test;  ← 删除名为test的数据库
Query OK, 0 rows affected (0.01 sec)
 
mysql> show databases;      ← 查看已存在的数据库
Empty set (0.01 sec)       
 
                  ← 确认test数据库已被删除(这里非root用户的关系,看不到名为mysql的数据库)
 
mysql> exit   ← 退出MySQL服务器
Bye
 
 
 
然后,删除测试用过的遗留用户
 
[root@192 local]# mysql -u root -p;
Enter password: 
mysql>  revoke all privileges on *.* from centospub@localhost;
 
                                           ← 取消centospub用户对数据库的操作权限
Query OK, 0 rows affected (0.01 sec)
 
 
mysql> delete from mysql.user where user='centospub'and host='localhost';
 
                                           ← 删除centospub用户
Query OK, 1 row affected (0.14 sec)
 
mysql> select user from mysql.user where user='centospub';
 
                          ← 查找用户centospub,确认已删除与否
Empty set (0.01 sec)      ← 确认centospub用户已不存在
 
mysql> flush privileges;  ← 刷新,使以上操作生效
Query OK, 0 rows affected (0.00 sec)
 
mysql> exit;
Bye
 
[root@192 local]# /etc/rc.d/init.d/httpd restart ← 重新启动HTTP服务
                                                 ← 注意:语句后面无需;分号
停止 httpd:                                               [确定]
启动 httpd:                                               [确定]
 
 
 
   第四篇:日志位置和网络服务器 
 一、日志位置
 
mysql 默认的日志位置,mysql日志文件默认存放位置 /var/log/mysqld.log
 
[root@192 ~]# cd /var/log
[root@192 log]# pwd
/var/log
[root@192 log]# ls
acpid                  boot.log.2       conman.old  dmesg    maillog          messages.2    ppp             samba                setroubleshoot   tallylog
anaconda.log      boot.log.3        cron             faillog     maillog.1       messages.3   prelink        scrollkeeper.log   spooler              vbox
anaconda.syslog  boot.log.4        cron.1         gdm        maillog.2       messages.4   rpmpkgs      secure               spooler.1           wtmp
anaconda.xlog     brcm-iscsi.log  cron.2         httpd       maillog.3      mysqld.log     rpmpkgs.1    secure.1            spooler.2            xen
audit                   btmp               cron.3         lastlog     maillog.4      news             rpmpkgs.2    secure.2            spooler.3           Xorg.0.log
boot.log              clumond.log     cron.4         libvirt       messages     piranha          rpmpkgs.3   secure.3            spooler.4          Xorg.0.log.old
boot.log.1           conman           cups            mail         messages.1  pm                rpmpkgs.4    secure.4             squid                yum.log
 
 
 
二、数据库服务器
 
mysql是支持网络的数据库服务器,经常需要通过互联网去访问,mysql默认使用tcp协议,端口是3306
 
 
 
[root@192 log]# cat mysqld.log
130503 11:25:03  mysqld started
InnoDB: The first specified data file ./ibdata1 did not exist:
InnoDB: a new database to be created!
130503 11:25:07  InnoDB: Setting file ./ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
130503 11:25:09  InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 5 MB
InnoDB: Database physically writes the file full: wait...
130503 11:25:09  InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 5 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
130503 11:25:12  InnoDB: Started; log sequence number 0 0
130503 11:25:12 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.0.95'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Source distribution
[root@192 log]# netstat -tupln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name  
tcp        0      0 127.0.0.1:2208                           0.0.0.0:*                   LISTEN       3569/hpiod         
tcp        0      0 0.0.0.0:5989                               0.0.0.0:*                   LISTEN       3905/cimserver     
tcp        0      0 0.0.0.0:11111                             0.0.0.0:*                   LISTEN       4783/ricci         
tcp        0      0 0.0.0.0:3306                               0.0.0.0:*                   LISTEN       3549/mysqld        
tcp        0      0 0.0.0.0:111                                 0.0.0.0:*                   LISTEN       2854/portmap       
tcp        0      0 0.0.0.0:80                                   0.0.0.0:*                   LISTEN       13747/httpd        
tcp        0      0 0.0.0.0:16851                             0.0.0.0:*                   LISTEN       4669/modclusterd   
tcp        0      0 192.168.122.1:53                       0.0.0.0:*                   LISTEN       3888/dnsmasq       
tcp        0      0 0.0.0.0:22                                   0.0.0.0:*                   LISTEN       3590/sshd          
tcp        0      0 127.0.0.1:631                             0.0.0.0:*                   LISTEN       3602/cupsd         
tcp        0      0 0.0.0.0:952                                 0.0.0.0:*                   LISTEN       2890/rpc.statd     
tcp        0      0 127.0.0.1:25                                0.0.0.0:*                   LISTEN      3643/sendmail: acce
tcp        0      0 0.0.0.0:443                                  0.0.0.0:*                   LISTEN      13747/httpd        
tcp        0      0 127.0.0.1:2207                            0.0.0.0:*                   LISTEN      3574/python        
udp        0      0 0.0.0.0:946                                 0.0.0.0:*                                    2890/rpc.statd     
udp        0      0 192.168.122.1:53                       0.0.0.0:*                                    3888/dnsmasq       
udp        0      0 0.0.0.0:949                                0.0.0.0:*                                     2890/rpc.statd     
udp        0      0 0.0.0.0:67                                  0.0.0.0:*                                     3888/dnsmasq       
udp        0      0 0.0.0.0:68                                  0.0.0.0:*                                     4516/dhclient      
udp        0      0 0.0.0.0:5353                             0.0.0.0:*                                      3846/avahi-daemon: 
udp        0      0 0.0.0.0:111                               0.0.0.0:*                                      2854/portmap       
udp        0      0 0.0.0.0:631                               0.0.0.0:*                                      3602/cupsd         
udp        0      0 0.0.0.0:34943                           0.0.0.0:*                                      3846/avahi-daemon: 

centOS Linux下用yum安装mysql的更多相关文章

  1. linux下使用yum安装mysql、tomcat、httpd

    一.linux下使用yum安装mysql   1.安装 查看有没有安装过:           yum list installed mysql*           rpm -qa | grep m ...

  2. [mysql] linux下使用yum安装mysql

    From: http://www.2cto.com/database/201207/141878.html linux下使用yum安装mysql   1.安装 查看有没有安装过:           ...

  3. linux下,yum 安装mysql

    顺手记录一下安装mysqlclient 先安装mysql-devel yum install mysql-devel 再安装mysqlclient pip3 install mysqlclient 开 ...

  4. linux下使用yum安装mysql详解

    1.安装客户端和服务器端 确认mysql是否已安装: ? 1 2 yum list installed mysql* rpm -qa | grep mysql* 查看是否有安装包: ? 1 yum l ...

  5. linux下使用yum安装mysql

    1. 安装mysql 服务器端:           yum install mysql-server             yum install mysql-devel 2. 安装mysql客户 ...

  6. CentOS 7.0下使用yum安装MySQL

    CentOS7默认数据库是mariadb,配置等用着不习惯,因此决定改成mysql,但是CentOS7的yum源中默认好像是没有mysql的.为了解决这个问题,我们要先下载mysql的repo源. 1 ...

  7. CentOS 7下源码安装MySQL 5.7

    网上说linux安装mysql服务分两种安装方法: ①源码安装,优点是安装包比较小,只有几十M左右,缺点是安装依赖的库多,安装编译时间长,安装步骤复杂容易出错: ②使用官方编译好的二进制文件安装,优点 ...

  8. centos7下使用yum安装mysql

    CentOS7的yum源中默认好像是没有mysql的.为了解决这个问题,我们要先下载mysql的repo源. 1. 下载mysql的repo源 wget http://repo.mysql.com/m ...

  9. CentOS 系统下使用 yum 安装 Redis

    本文主要介绍在 CentOS 7 系统下使用 yum 安装 Redis 的过程. 更改 yum 源 将 Centos 的 yum 源更换为国内的阿里云源. 首先备份你的原镜像文件,保证出错后可以恢复: ...

随机推荐

  1. redis 主从备份自动切换+java代码实现类

    转载:http://blog.csdn.net/qq_23430789/article/details/52185706 目录(?)[-] redis-0sentinel实例之间的通讯端口 maste ...

  2. 论文笔记:目标追踪-CVPR2014-Adaptive Color Attributes for Real-time Visual Tracking

    基于自适应颜色属性的目标追踪 Adaptive Color Attributes for Real-Time Visual Tracking 基于自适应颜色属性的实时视觉追踪 3月讲的第一篇论文,个人 ...

  3. C++学习之普通函数指针与成员函数指针

    函数指针(function pointer)是通过指向函数的指针间接调用函数.相信很多人对指向一般函数的函数指针使用的比较多,而对指向类成员函数的函数指针则比较陌生.我最近也被问到了这方面的问题,心中 ...

  4. C#程序猿学习 Python

    孙广东  2016.1.1 交互: C# 运行Python代码: http://stackoverflow.com/questions/11779143/run-a-python-script-fro ...

  5. 500万url的es 批删除

    bash  循环 算术计算 读写文件 [root@hadoop2 ~]# sh looh.sh1234LIZ1 2 3 4 0 1 2 3 4 5 6 7 8 9 10 0games:x:12:100 ...

  6. bzoj4668

    并查集+最小生成树 首先我们发现这题可以lct维护最小生成树,但是发现如果生成树在之后是不会修改的,那么就想到了并查集,然后就不知道怎么做了... 其实当我们连接两个连通块的时候,两个连通块只能通过这 ...

  7. MySQL之自定义函数实例讲解

    转自:https://www.2cto.com/database/201804/740205.html MySQL中已经有很多函数,如时间函数等,但是有时这些函数不能满足自己的设计需求,此时需要自定义 ...

  8. android 中activity 属性说明(转载)

    转自:http://liuwuhen.iteye.com/blog/1759796 activity是android中使用非常平凡的一种组件,我们除了需要掌握activity中的生命周期以外,还需要掌 ...

  9. bzoj4563: [Haoi2016]放棋子(错排+高精)

    4563: [Haoi2016]放棋子 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 387  Solved: 247[Submit][Status] ...

  10. 我们的微信小程序开发

    基于微信小程序的系统开发准备工作 腾讯推出微信小程序也有一段时间了,在各种行业里面也都掀起一阵阵的热潮,很多APP应用被简化为小程序的功能迅速推出,同时也根据小程序的特性推出各种独具匠心的应用,相对传 ...