日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

如何用linux登入数据库,Linux中MySQL数据库的使用①-----登录、数据库操作、表结构操作...

發(fā)布時間:2023/12/19 数据库 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 如何用linux登入数据库,Linux中MySQL数据库的使用①-----登录、数据库操作、表结构操作... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

啟動mysql服務(wù)

systemctl start mysqld

登錄mysql

mysql -u root -p # 登錄本機(jī)

mysql -u root -hlocalhost -P3306 -p # 登錄指定地址

CentOS登錄mysql時需要輸入系統(tǒng)給里的l臨時密碼:

cat /var/log/mysqld.log |grep password

登錄進(jìn)來后因為是臨時密碼,所以不能進(jìn)行操作。需要改密碼后才能使用數(shù)據(jù)庫。

alter user root@localhost identified with mysql_native_password by 'Yyjhbb020814@';

忘記密碼怎么辦?

打開/etc/my.cnf配置文件

vim /etc/my.cnf

#在里面加一句

[mysqld]

skip-grant-tables

如果文件中已經(jīng)存在[mysqld],則直接將skip-grant-tables寫到下方即可。

然后重啟mysqld服務(wù)

systemctl restart mysqld

此時已經(jīng)可以無密碼登錄mysql

沒有密碼很不安全,因此需要更新mysql密碼

update mysql.user set authentication_string=password('密碼') where user='root';

一、常用操作

1.創(chuàng)建用戶,授予權(quán)限

GRANT ALL PRIVILEGES on *.* to 'maxin'@'localhost' IDENTIFIED BY "Mxin19981024@" WITH GRANT OPTION;

grant:授予

all privileges:所有權(quán)限

*.*:所有數(shù)據(jù)庫里的所有表

maxin@localhost:用戶maxin允許本機(jī)登錄

identified by “Mxin19981024@”:密碼

with grant option:他的權(quán)限可以向下傳遞

2.查看權(quán)限

show grants;

show grants for 'root'@'localhost'; # 查看指定用戶的權(quán)限

3.回收權(quán)限

#回收用戶的所有權(quán)限

revoke all privileges on *.* from '用戶'@'localhost';

#回收權(quán)限的傳遞

revoke grant option on *.* from '用戶'@'localhost';

4.刪除用戶

drop user 用戶@localhost;

二、數(shù)據(jù)庫的操作

1.查看數(shù)據(jù)庫

show databases;

2.創(chuàng)建數(shù)據(jù)庫

create database [if not exists] 數(shù)據(jù)庫名 charset=utf8;

3.使用數(shù)據(jù)庫

use 數(shù)據(jù)庫名;

4.修改數(shù)據(jù)庫

alter database 數(shù)據(jù)庫名 charset=字符集; #只能修改字符集

5.刪除數(shù)據(jù)庫

drop database [if exists] 數(shù)據(jù)庫名;

三、表的操作

1.創(chuàng)建表

create table [if not exists] 表名(

id int not null auto_increment primary key comment '主鍵',

name varchar(128) not null,

age int

)charset=utf8;

2.查看表結(jié)構(gòu)

desc 表名;

show create table 表名; # 查看建表語句

3.刪除表

drop table 表名;

4.修改表結(jié)構(gòu)

alter table 表名 rename 新表名; # 改表名

alter table 表名 rename to 數(shù)據(jù)庫.新表名; # 將表移動到另一個數(shù)據(jù)庫中

alter table 表名 add 字段名 類型; # 新增字段

alter table 表名 modify 字段名 屬性; # 修改屬性

alter table 表名 change 字段名 新字段名 屬性; # 用來修改字段名

alter table 表名 drop 字段名; # 刪除字段

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結(jié)

以上是生活随笔為你收集整理的如何用linux登入数据库,Linux中MySQL数据库的使用①-----登录、数据库操作、表结构操作...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。