首页 > 代码库 > liunx 下mysql 安装使用

liunx 下mysql 安装使用

#1.停止mysql数据库
/etc/init.d/mysqld stop
#2.执行如下命令
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
#3.使用root登录mysql数据库
mysql -u root mysql
#4.更新root密码
mysql> UPDATE user SET Password=PASSWORD(‘newpassword‘) where USER=‘root‘;
#5.刷新权限
mysql> FLUSH PRIVILEGES;
#6.退出mysql
mysql> quit
#7.重启mysql
/etc/init.d/mysqld restart
#8.使用root用户重新登录mysql
mysql -uroot -p
Enter password: <输入新设的密码newpassword>


    MySQL安装
    安装
rpm -ivh mysql-community-common-5.7.10-1.el6.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-libs-5.7.10-1.el6.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-client-5.7.10-1.el6.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-server-5.7.10-1.el6.x86_64.rpm --force --nodeps

启动
service mysqld start
停止
service mysqld stop

使用安全模式启动
mysqld_safe --user=mysql --skip-grant-tables --skip-networking&
mysql  /**进入mysql交互窗口*
UPDATE mysql.user SET authentication_string=PASSWORD(‘root‘) where USER=‘root‘;  
/*5.7之后的版本user表中没有password字段*/
flush privileges;
exit;
退出安全模式:
service mysqld stop

修改mysql编码,同时修改密码安全级别:
vi /etc/my.cnf

# reset pass level
validate_password_policy = 0
validate_password_length = 1
validate_password_mixed_case_count = 0
validate_password_number_count = 0
validate_password_special_char_count = 0

character_set_server=utf8
default-storage-engine=INNODB
collation-server=utf8_general_ci

[client]
default-character-set=utf8


启动
service mysqld start
加入开机启动
chkconfig mysqld on
mysql -uroot -p

执行sql命令
SET PASSWORD = PASSWORD(‘root‘);
flush privileges;

use mysql;
delete from user;
授权
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘localhost‘ IDENTIFIED BY ‘root‘ WITH GRANT OPTION;本地
GRANT ALL PRIVILEGES ON *.* TO ‘ root‘@‘%‘ IDENTIFIED BY ‘root‘ WITH GRANT OPTION;
远程
刷新权限
flush privileges;

创建HIVE连接用户:
mysql -uroot -proot
create database hive DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
授权本地连接:
GRANT ALL PRIVILEGES ON hive.* TO ‘hive‘@‘localhost‘ IDENTIFIED BY ‘hive‘ WITH GRANT OPTION;
授权远程连接:
GRANT ALL PRIVILEGES ON hive.* TO ‘hive‘@‘%‘ IDENTIFIED BY ‘hive‘ WITH GRANT OPTION;
提交:
FLUSH PRIVILEGES;

liunx 下mysql 安装使用