首先记一条命令:
查找设备IP地址:/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"
安装完MySQL后设置root的密码:mysqladmin -u root -h host_name password "newpwd" password后面的双引号不是必须的
默认密码为空
有时会出现错误:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
解决办法如下:
# /etc/init.d/mysqld stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root' and host='root' or host='localhost';
mysql> FLUSH PRIVILEGES;
mysql> quit
# /etc/init.d/mysqld restart
# mysql -uroot -p
Enter password: <输入新设的密码newpassword>
建库和建表:
create database 库名;
create table 表名;
删库和删表:
drop database 库名;
drop table 表名;
将表中记录清空:
delete from 表名;
建表:
create table iso_list(id int(4) not null primary key auto_increment,iso_name char(40) not null,iso_path char(40) not null,distro_name char(40) not null,distro_arch char(40) not null);
先删除在插入:
mysql -uroot -hlocalhost -p123456 -P3306 auto_matic_configuration -e "delete from computer_info where ip='$i';insert into computer_info values(0,'$i', '$mac_addr', 0, NULL, NULL, NULL, 'lease_watch', '$lease_start')"
根据条件插入:
insert into computer_info(ip ,mac_addr ,os_flag , update_user , update_time) select '12.13.1.1', 'mac_addr', 0, 'lease_watch', 'lease_start' from dual where not exists(select mac_addr from computer_info where mac_addr='mac_addr');
导入MySQL:
drop database cloud_service_manage;
create database cloud_service_manage default character set utf8;
use cloud_service_manage;
source /home/kvm_demo/web_server/sql/cloud_service_manage.sql;
show tables;
select * from catalogue;
MySQL设置远程登录
1.修改mysql数据库的配置,包括:设置mysql下密码、禁用远程访问,删除无用账户及测试数据库
mysql_secure_installation
2.mysql设置远程登录:
(1)本地登录mysql
mysql -uroot -p
(2)查询user表确认
mysql> use mysql; (此DB存放MySQL的各种配置信息)
Database changed
mysql> select host,user from user; (查看用户的权限情况)
+-------------+-------+
| host | user |
+-------------+-------+
| localhost | |
| localhost | root |
| localhost | |
| localhost | mysql |
+-------------+-------+
6 rows in set (0.02 sec)
由此可以看出,只能以localhost的主机方式访问。
(3)设置权限
mysql> Grant all privileges on *.* to 'root'@'%' identified by ‘password’with grant option;
(%表示是所有的外部机器,如果指定某一台机,就将%改为相应的机器名;‘root’则是指要使用的用户名,里面的password需要自己修改成root的密码)
mysql> flush privileges; (运行为句才生效,或者重启MySQL)
(4)确认权限赋值成功
mysql> select host,user from user;
+------------------+------+
| host | user |
+------------------+------+
| % | root |
| 127.0.0.1 | root |
| localhost | |
| localhost | root |
| xxjcsyb.cloud90c | |
| xxjcsyb.cloud90c | root |
+------------------+------+
6 rows in set (0.00 sec)
阅读(1040) | 评论(0) | 转发(0) |