成都创新互联网站制作重庆分公司

MYSQL安装的简单教程

下面一起来了解下MySQL安装的简单教程,相信大家看完肯定会受益匪浅,文字在精不在多,希望MYSQL安装的简单教程这篇短内容是你想要的。

成都创新互联专注于企业全网营销推广、网站重做改版、进贤网站定制设计、自适应品牌网站建设、H5网站设计成都商城网站开发、集团公司官网建设、成都外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为进贤等各大城市提供网站开发制作服务。

root@localhost ~]# mysql -uroot -p

Enter password:

MariaDB [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| db2                |

| mysql              |

| performance_schema |

+--------------------+

4 rows in set (0.01 sec)

 MYSQL安装的简单教程

MariaDB [(none)]> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

 

Database changed

MariaDB [mysql]> show tables;

+---------------------------+

| Tables_in_mysql           |

+---------------------------+

| columns_priv              |

| db                    

MariaDB [mysql]> select user from user;

+------+

| user |

+------+

| lee  |

| root |

| root |

| root |

+------+

4 rows in set (0.00 sec)

 

MariaDB [mysql]> select * from user;

+-----------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+--------+-----------------------+

MariaDB [mysql]> desc user;

+------------------------+-----------------------------------+------+-----+---------+-------+

| Field                  | Type                              | Null | Key | Default | Extra |

+------------------------+-----------------------------------+------+-----+---------+-------+

| Host                   | char(60)                          | NO   | PRI |         |       |

| User                   | char(16)                          | NO   | PRI |         |       |

| Password               | char(41)                          | NO   |     |         |       |

| Select_priv            | enum('N','Y')                     | NO   |     | N    

yum install -y mariadb-server

systemctl start mariadb

mysql

netstat -antlpe | grep mysql

vim /etc/my.cnf

[mysqld]模块下添加

skip-networking=1   ##关闭数据库在网络上开启的端口,加锁 防止别人进攻 这是端口看不到了

systemctl restart mariadb

netstat -antlpe | grep mysql

mysql

mysql_secure_installation 设置密码 匿名用户不能登陆 远程不能登陆等

mysql -uroot -p

redhat  密码 

MariaDB [(none)]> create database westos;

Query OK, 1 row affected (0.00 sec)

MariaDB [westos]> create table linux(

    -> username varchar(15) not null,

    -> password varchar(15) not null

    -> );

Query OK, 0 rows affected (0.04 sec)

 

MariaDB [westos]> show tables;

+------------------+

| Tables_in_westos |

+------------------+

| linux            |

+------------------+

1 row in set (0.00 sec)

 

MariaDB [westos]> insert into linux values ('user1','123');

Query OK, 1 row affected (0.01 sec)

 

MariaDB [westos]> insert into linux values ('user2',password('123'));

Query OK, 1 row affected, 1 warning (0.04 sec)      对密码进行加密

 

MariaDB [westos]> select * from linux;

+----------+-----------------+

| username | password        |

+----------+-----------------+

| user1    | 123             |

| user2    | *23AE809DDACAF9 |

+----------+-----------------+

2 rows in set (0.00 sec)

 

 

MariaDB [westos]> update linux set password=password('234') where username='user1';

Query OK, 1 row affected, 1 warning (0.61 sec)

Rows matched: 1  Changed: 1  Warnings: 1

 

MariaDB [westos]> delete from linux where username='user1';

Query OK, 1 row affected (0.02 sec)

MariaDB [westos]> alter table linux add age varchar(4);

Query OK, 1 row affected (0.11 sec)                

Records: 1  Duplicates: 0  Warnings: 0

 

MariaDB [westos]> select * from linux;

+----------+-----------------+------+

| username | password        | age  |

+----------+-----------------+------+

| user2    | *23AE809DDACAF9 | NULL |

+----------+-----------------+------+

1 row in set (0.00 sec)

MariaDB [westos]> alter table linux drop age;

Query OK, 1 row affected (0.40 sec)                

Records: 1  Duplicates: 0  Warnings: 0

 

MariaDB [westos]> select * from linux;

+----------+-----------------+

| username | password        |

+----------+-----------------+

| user2    | *23AE809DDACAF9 |

+----------+-----------------+

1 row in set (0.00 sec)

 

MariaDB [westos]> alter table linux add age varchar(5) after username;

Query OK, 1 row affected (0.10 sec)                

Records: 1  Duplicates: 0  Warnings: 0

 

MariaDB [westos]> select * from linux;

+----------+------+-----------------+

| username | age  | password        |

+----------+------+-----------------+

| user2    | NULL | *23AE809DDACAF9 |

MariaDB [westos]> alter table linux drop age;

MariaDB [westos]> delete from linux where username='user1';

Query OK, 0 rows affected (0.00 sec)

 

MariaDB [westos]> drop table linux;

Query OK, 0 rows affected (0.32 sec)

 

MariaDB [westos]> drop database westos;

Query OK, 0 rows affected (0.00 sec)

 

MariaDB [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| db2                |

| mysql              |

| performance_schema |

+--------------------+

4 rows in set (0.00 sec)

Query OK, 1 row affected (0.41 sec)                

 

[root@localhost ~]# mysqldump -u root -predhat westos

[root@localhost ~]# mysqldump -u root -predhat westos > /mnt/westos.sql

[root@localhost ~]# mysql -uroot -predhat -e "drop database westos;"

[root@localhost ~]# mysql -uroot -p

Enter password:

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 15

Server version: 5.5.35-MariaDB MariaDB Server

 

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

MariaDB [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| db2                |

| mysql              |

| performance_schema |

+--------------------+

4 rows in set (0.01 sec)

 

MariaDB [(none)]> mysql -uroot -predhat -e "create database westos;"

    -> Ctrl-C -- exit!

Aborted

[root@localhost ~]# mysql -uroot -predhat -e "create database westos;"

[root@localhost ~]# mysql -uroot -predhat westos< /mnt/westos.sql

[root@localhost ~]# mysql -uroot -predhat -e "select * from westos.linux;"

+----------+----------+

| username | password |

+----------+----------+

| user1    | 123      |

| user2    | 456      |

+----------+----------+

 

MariaDB [(none)]> create user lee@localhost identified by 'lee';

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant insert,update,delete,select on westos.linux to lee@localhost;

Query OK, 0 rows affected (0.00 sec)

 

MariaDB [(none)]> grant select on westos.* to lee@'%';

Query OK, 0 rows affected (0.00 sec)

 

MariaDB [(none)]> show grants for lee@'%';

+----------------------------------------------------------------------------------------------------+

| Grants for lee@%                                                                                   |

+----------------------------------------------------------------------------------------------------+

| GRANT USAGE ON *.* TO 'lee'@'%' IDENTIFIED BY PASSWORD '*28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96' |

| GRANT SELECT ON `westos`.* TO 'lee'@'%'                                                            |

+----------------------------------------------------------------------------------------------------+

2 rows in set (0.00 sec)

 

MariaDB [(none)]> revoke delete on westos.linux from lee@localhost;

Query OK, 0 rows affected (0.00 sec)

 

MariaDB [(none)]> drop user lee@'localhost';

Query OK, 0 rows affected (0.00 sec)

 

[root@localhost ~]# mysqladmin -uroot -pwestos password redhat

[root@localhost ~]# systemctl stop mariadb.service

[root@localhost ~]# ps aux | grep mysql

root      5724  0.0  0.0 112640   980 pts/1    S+   01:53   0:00 grep --color=auto mysql

[root@localhost ~]# mysqld_safe --skip-grant-tables &

[1] 5744

[root@localhost ~]# killall -9 mysqld_safe

[1]+  Killed                  mysqld_safe --skip-grant-tables

[root@localhost ~]# ps aux | grep mysql

[root@localhost ~]# kill -9 6019

[root@localhost ~]# ps aux | grep mysql

root      6083  0.0  0.0 112640   980 pts/1    R+   02:02   0:00 grep --color=auto mysql

[root@localhost ~]# systemctl start mariadb

 

@@@@@@@@@@   用网页 鼠标点一点便可建立数据库 插入表 删除表数据库等等

lftp 172.25.254.250:/pub/docs/software> get phpMyAdmin-3.4.0-all-languages.tar.bz2

4548030 bytes transferred                                           

lftp 172.25.254.250:/pub/docs/software> quit

[root@localhost ~]# ls

anaconda-ks.cfg  lala.py                                 Public

backup.dump      linux.dump                              Templates

Desktop          Music                                   Videos

Documents        phpMyAdmin-3.4.0-all-languages.tar.bz2  westos.dump

Downloads        Pictures

[root@localhost ~]# tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2 -C /var/www/html/

[root@localhost ~]# ls

anaconda-ks.cfg  lala.py                                 Public

backup.dump      linux.dump                              Templates

Desktop          Music                                   Videos

Documents        phpMyAdmin-3.4.0-all-languages.tar.bz2  westos.dump

Downloads        Pictures

[root@localhost ~]# cd /var/www/html/

[root@localhost html]# ls

phpMyAdmin-3.4.0-all-languages

[root@localhost html]# mv phpMyAdmin-3.4.0-all-languages/ mysqladmin

 

ot@localhost html]# ls

mysqladmin

[root@localhost html]# cd mysqladmin/

[root@localhost mysqladmin]# ls

browse_foreigners.php     main.php                server_status.php

bs_disp_as_mime_type.php  navigation.php          server_synchronize.php

bs_play_media.php         phpdoctor.ini           server_variables.php

........

[root@localhost mysqladmin]# cp -p config.sample.inc.php config.inc.php

[root@localhost mysqladmin]# vim config.inc.php

17 $cfg['blowfish_secret'] = 'mysql'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH!     */

 

[root@localhost mysqladmin]# systemctl restart httpd

测试:

访问  http://172.25.254.170/mysqladmin

这是会看到phpMyAdmin 界面 这个时候选择中文root redhat

可以新建数据库 表 插入 删除表 等等

  

################     mysql   ######################################

数据库时有好多张表组成

 

yum install -y mariadb-server

systemctl start mariadb

mysql

netstat -antlpe | grep mysql   会看到3306端口

vim /etc/my.cnf

[mysqld]模块下添加

skip-networking=1   ##关闭数据库在网络上开启的端口,加锁 防止别人进攻 这是端口看

不到了 这样别人就不能***修改数据库上的数据了  1表有效

systemctl restart mariadb

netstat -antlpe | grep mysql  这时看不到3306端口了

mysql_secure_installation  设置root密码 匿名用户不能登陆 远程不能登陆

mysql -uroot -p

redhat 输入mysql的密码

  

@@@@@@@@@@@@  数据库的基本sql语句操作  @@@@@@@@@@@@@@@@

1 登陆

mysql -uroot -predhat

2 查询

show databases;  显示数据库

use mysql;       进入mysql数据库

show tables;     显示当前库中表的名称

select * from user; 查询user表中的所有内容(*可以用此表中的任何字段表示)

desc user; 查询user表的结构(显示所有字段的名称)

 

3数据库及表的建立

create database westos   创建westos库

create table linux(      创建linux表 并且linux表含有两个字段username password

username varchar(15) not null, username字段 字符长度最大15个,并且不能为空

password varchar(15) not null

);                     

insert into linux values ('user1','123');  向linux表中插入数据,username字段的数据为user1

insert into linux values ('user2',password('123')); 插入password字段的数据是用password加密过的

 

4更新数据库信息

update linux set password=password('passwd2') where username='user1';

更新user1的密码

delete from linux where username='user1';  删除user1信息

alter table linux add age varchar(4);      添加age字段到linux表的最后一列

alter table linux add age varchar(5) after name;  添加age字段在name字段之后

alter table linux drop age;  删除age字段

 

5删除数据库

delete from linux where username='user1'; 删除user1的数据从linux表中

drop table linux;    删除linux表

drop database westos;   删除westos数据库

 

6 数据库的备份

mysqldump -u root -predhat --all-database  备份所有表中的所有数据

mysqldump -u root -predhat --all-database --no-database --no-data 备份所有表但不备份数据

mysqldump -u root -predhat westos   备份westos数据库

mysqldump -u root -predhat westos > /mnt/westos.sql

备份westos数据库并把数据保存到westos.sql中

mysqldump -u root -predhat westos linux > /mnt/linux.sql

备份mysql中的linux表

mysql -uroot -predhat -e "create database westos;"  建立westos库

mysql -uroot -predhat westos < /mnt/westos.sql 把数据导入westos库

 

7用户授权   必须用超级用户

create user lee@localhost identified by 'lee'; 建立用户lee,此用户只能通过本机登陆

create user lee@'%' identified by 'lee'; 建立用户lee,此用户可以通过网络登录

grant insert,update,delect,select on westos.test to lee@localhost;

用户授权  授权westos数据库的test表可以通过localhost主机登陆lee用户

grant select on westos.* to lee@'%';

show grants for lee@'%'  查看用户授权

show grants for lee@localhost

revoke delete on westos.test from lee@localhost; 去除用户授权权力

drop user lee@'%';   删除用户

 

8修改密码

mysqladmin -uroot -predhat password lee

忘记超级用户密码时的操作

mysqld_safe --skip-grant-tables &  开启mysql登陆接口并忽略授权表

mysql      直接不用密码可以登陆

update mysql.user set Password=password('123') where User='root';

更新超级用户密码信息

ps aux | grep mysql   过滤mysql的所有进程并结束这些进程

kill -9 mysqlpid

systemctl start mariadb   重新开启mysql

mysql -uroot -p123    登陆测试

1安装

yum install -y httpd php php-mysql

systemctl start httpd

systemctl enable httpd

systemctl stop firewalld

systemctl disable firewalld

下载 phpMyAdmin-3.4.0-all-languages.tar.bz2

tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2 -C /var/www/html解压到指定目录

cd /var/www/html

mv phpMyAdmin-3.4.0-all-languages mysqladmin

cd mysqladmin

cp -p config.sample.inc.php config.inc.php

vim config.inc.php

17 $cfg['blowfish_secret']= 'mysql'; /* YOU MUST FILL IN THIS FOR COOKIEAUTH! */

systemctl restrt httpd

测试:

访问http://172.25.254.170/mysqladmin

会看到phpadmin界面 用鼠标点一点即可创建数据库 添加字段 删除表等 同时还会同步到命令行中 用命令可以在命令行中看到 相当于用命令创建 删除增添 但是phpmyadmin方便快捷

看完MYSQL安装的简单教程这篇文章后,很多读者朋友肯定会想要了解更多的相关内容,如需获取更多的行业信息,可以关注我们的行业资讯栏目。


文章名称:MYSQL安装的简单教程
标题网址:http://cxhlcq.com/article/igjppp.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部