Linux 数据库
来源:互联网 发布:linux 恢复删除的文件 编辑:程序博客网 时间:2024/05/18 03:47
1.安装数据库需要的软件
yum groupinstall -y mariadb-server mariadb-client ##安装mariadb和mariadb-client组件
systemctl start mariadb 启动mariadb服务:
systemctl enable mariadb
ss -antlp |grep mysql ##校验mariadb的监听端口
vim /etc/my.cnf
[mysqld]...skip-networking=1...
systemctl restart mariadb
ss -antlp |grep mysql ##此时只允许通过套接字文件进行本地连接,阻断所有来自网络的tcp/ip连接
2.运行mysql
1)登陆
mysqladmin -uroot -predhat password westos ##修改本地mysql root密码
mysqladmin -uroot -predhat -h 192.168.0.188 password westos ##修改远程192.168.0.188 mysql服务器 root密码
mysql_secure_installation ##第一次安装mysql以后通过这条命令可以对mysql进行设置
mysql -uroot -predhat ##从本机登录mysql数据库
2)使用mysql
[root@server mnt]# mysql -uroot -pEnter password: Welcome to the MariaDB monitor. Commands end with ; or \g.Your MariaDB connection id is 6Server version: 5.5.35-MariaDB MariaDB ServerCopyright (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 || mysql || performance_schema |+--------------------+3 rows in set (0.04 sec)MariaDB [(none)]> QUITBye[root@server mnt]#
3.SQL常用语句
SHOW DATABASES; ##显示数据库USE mysql; ##进入数据库SHOW TABLE; ##显示数据库中的表DESC user; ##查看user表的数据结构FLUSH PRIVILEGES; ##刷新数据库信息SELECT host.user,password FROM user; ##查询user表中的host,user,password字段CREATE DATEBASE westos; ##创建westos数据库USE westos; CREATE TABLE linux( ##创建表,username,password字段username varchar(15) not null,password varchar(15) not null);SELECT * FROM mysql.user; ##查询mysql库下的user表中的所以ALTER TABLE linux ADD age varchar(4); ##添加age字段到linux表中ALTER TABLE linux DROP age ##删除age字段ALTER TABLE linux ADD age VARCHAR(5) AFTER name ##在name字段后添加字段ageSHOW TABLE;DESC linux;INSERT INTO linux VALUES ('user1','passwd1'); ##在linux表中插入值为username = user1,password = password1UPDATE linux SET password=password('passwd2') WHERE username=user1; ##更新linux表中user1 的密码为password2DELETE FROM linux where username=user1; ##删除linux表中user1的所以内容GRANT SELECT ON *.* to user1@localhost IDENTIFIED BY 'passwd1'; ##授权user1 密码为passwd1 并且只能在本地 查询数据库的所以内容 GRANT ALL ON mysql.* to user2@'%' IDENTIFIED BY 'passwd2'; ##授权user2 密码为passwd2 可以从远程任意主机登录mysql 并且可以对mysql数据库任意操作
4.数据库备份和密码找回
1)数据库备份
/var/lib/mysql
mysqldump -uroot -predhat mysql > mysql.bak 备份mysql库到mysql.bak
mysql -uroot -predhat westos < mysql.bak 恢复mysql.bak 到westos库
2)密码找回
systemctl stop mariadb ##关闭数据库服务
mysqld_safe –skip-grant-tables & 跳过grant-tables授权表 不需要认证登录本地mysql数据库
update mysql.user set password=password(‘westos’) where user=’root’; 更新mysql.user 表中条件为root用户的密码为加密westos
quit
ps aux | grep mysql
kill -q 11352 ##查找并结束之前数据库的进程
systemctl restart mariadb ##重起服务
- linux 数据库
- linux 数据库
- Linux 数据库
- linux 数据库
- Linux下启停数据库服务
- Linux编程之数据库
- linux 启动mysql 数据库
- linux备份mysql数据库
- linux odbc 访问数据库
- linux 下手动起停数据库
- linux dbm数据库
- linux备份mysql数据库
- Linux 下重启Oracle 数据库
- linux 安装redis数据库
- linux oracle数据库操作
- linux下操作数据库
- linux 导入数据库 mysql
- linux启动oracle数据库
- Uva816
- Java 获得用户远程地址
- 23中设计模式之_状态模式
- 图解HTTP读书笔记
- 注重科技积累 三星手机以创新赢得地位与利润
- Linux 数据库
- 命令行中文乱码问题
- 高性能开发(2) Redis缓存实现分布式session共享(一)
- 直接拿来用!最火的Android开源项目
- PTA-整数分解为若干项之和
- Eclipse build errors
- 方便好使的java.util.Properties类
- MFC OCX开发笔记
- URL和URI的区别详谈