Mysql的常用操作
第一、 启动数据库
第一种方式:
linux-aku9:/etc/init.d # ./mysql stop
redirecting to systemctl stop
Shutting down MySQL.. done
linux-aku9:/etc/init.d # ./mysql start
redirecting to systemctl start
Starting MySQL. done
linux-aku9:/etc/init.d #
第二种方式:
linux-l7pk:~ # rcmysql start
redirecting to systemctl start mysql
第二、 设置数据库自动启动
第三、 登录mysql
mysql -u root -h 127.0.0.1
或者
mysql -u root -h localhost -p
然后输入root密码即可
第四、 创建数据库
CREATE DATABASE `openfire` CHARACTER SET 'utf8';
切换数据库
use openfire;
第五、 修改数据库的编码为UTF-8
alter database openfire default character set utf8 default collate utf8_general_ci;
alter database bbcam_mirror default character set utf8mb4 default collate utf8mb4_general_ci;
第六、 用数据库脚本手动刷库
mysql -u root -p BBCam < /home/yizhichao/bbcam.sql
mysql -u root -p BBCam < /home/yizhichao/bbcam_initdb.sql
mysql -u root -p openfire < /home/yizhichao/openfire_mysql.sql
mysql -u root -p MediaPlatDB < /opt/yizhichao/db/MediaPlatDB_initdb.sql
第七、 查看数据库连接
show processlist;
可以kill 连接进程
第八、 授权数据库网络访问
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'BBCam_Admin' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
第九、 数据库连接串
jdbc:mysql://localhost:3306/BBCam?useUnicode=true&characterEncoding=utf8
jdbc:mysql://localhost:3306/openfire?rewriteBatchedStatements=true&useUnicode=true&characterEncoding=utf8
第十、 修改用户密码
修改root密码
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('BBCam_Admin');
SET PASSWORD=PASSWORD('BBCam_Admin');
第十一、 关闭opensuse防火墙
linux-l7pk:~ # rcSuSEfirewall2 stop
linux-l7pk:~ #
第十二、 创建用户
CREATE USER 'bbcam'@'localhost' IDENTIFIED BY 'bbcam_2014';
GRANT ALL ON *.* TO 'bbcam'@'%';
CREATE USER 'bbcam'@'127.0.0.1' IDENTIFIED BY 'bbcam_2014';
CREATE USER 'openfire'@'localhost' IDENTIFIED BY 'openfire_2014';
GRANT ALL ON *.* TO 'openfire'@'%';
CREATE USER 'openfire'@'127.0.0.1' IDENTIFIED BY 'openfire_2014';