在Fedora 20 上安装Mysql并初始化root密码

时间:2024-04-15 09:07:39
[root@localhost ~]# yum -y install community-mysql-server #安装数据库

已加载插件:langpacks, refresh-packagekit
google-chrome /
正在解决依赖关系
There are unfinished transactions remaining. You might consider running yum-complete-transaction, or "yum-complete-transaction --cleanup-only" and "yum history redo last", first to finish them. If those don't work you'll have to try removing/installing packages by hand (maybe package-cleanup can help).
--> 正在检查事务
---> 软件包 community-mysql-server.x86_64.0.5.5.35-.fc20 将被 安装
--> 正在处理依赖关系 community-mysql-common(x86-) = 5.5.-.fc20,它被软件包 community-mysql-server-5.5.-.fc20.x86_64 需要
--> 正在处理依赖关系 mysql(x86-),它被软件包 community-mysql-server-5.5.-.fc20.x86_64 需要
--> 正在检查事务
---> 软件包 community-mysql.x86_64.0.5.5.35-.fc20 将被 安装
---> 软件包 community-mysql-common.x86_64.0.5.5.35-.fc20 将被 安装
--> 解决依赖关系完成 依赖关系解决 ================================================================================
Package 架构 版本 源 大小
================================================================================
正在安装:
community-mysql-server x86_64 5.5.-.fc20 updates 8.8 M
为依赖而安装:
community-mysql x86_64 5.5.-.fc20 updates 4.9 M
community-mysql-common x86_64 5.5.-.fc20 updates k 事务概要
================================================================================
安装 软件包 (+ 依赖软件包) 总下载量: M
安装大小: M
Downloading packages:
(/): community-mysql-5.5.-.fc20.x86_64.rpm | 4.9 MB :
(/): community-mysql-common-5.5.-.fc20.x86_64.rpm | kB :
(/): community-mysql-server-5.5.-.fc20.x86_64.rpm | 8.8 MB :
--------------------------------------------------------------------------------
总计 1.4 MB/s | MB :
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : community-mysql-common-5.5.-.fc20.x86_64 /
正在安装 : community-mysql-5.5.-.fc20.x86_64 /
正在安装 : community-mysql-server-5.5.-.fc20.x86_64 /
验证中 : community-mysql-5.5.-.fc20.x86_64 /
验证中 : community-mysql-server-5.5.-.fc20.x86_64 /
验证中 : community-mysql-common-5.5.-.fc20.x86_64 / 已安装:
community-mysql-server.x86_64 :5.5.-.fc20 作为依赖被安装:
community-mysql.x86_64 :5.5.-.fc20
community-mysql-common.x86_64 :5.5.-.fc20 完毕!
[root@localhost ~]# systemctl start mysqld.service
[root@localhost ~]# systemctl enable mysqld.service
ln -s '/usr/lib/systemd/system/mysqld.service' '/etc/systemd/system/multi-user.target.wants/mysqld.service'
[root@localhost ~]# mysql -u root #以root登陆数据库
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.5. MySQL Community Server (GPL) Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> select user, host, password from mysql.user; #user列表
+------+-----------+----------+
| user | host | password |
+------+-----------+----------+
| root | localhost | |
| root | rachel | |
| root | 127.0.0.1 | |
| root | :: | |
| | localhost | |
| | rachel | |
+------+-----------+----------+
rows in set (0.00 sec) mysql> delete from mysql.user where user=''; #删除空user
Query OK, rows affected (0.00 sec) mysql> delete from mysql.user where user='root' and host='::1'; #删除IPv6用户(如果不用的话)
Query OK, row affected (0.00 sec) mysql> select user, host, password from mysql.user;
+------+-----------+----------+
| user | host | password |
+------+-----------+----------+
| root | localhost | |
| root | rachel | |
| root | 127.0.0.1 | |
+------+-----------+----------+
rows in set (0.00 sec) # 设定密码
mysql> set password for root@localhost=password('XXXXXX');
Query OK, rows affected (0.00 sec) mysql> set password for root@rachel=password('XXXXXX');
Query OK, rows affected (0.00 sec) mysql> set password for root@'127.0.0.1'=password('XXXXXXX');
Query OK, rows affected (0.00 sec) #再次列密码
mysql> select user, host, password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| root | localhost | *C7E2F6338326EDC0AXXXXXXXXXXXXXXXXXXXXXXX |
| root | rachel | *C7E2F6338326EDC0AXXXXXXXXXXXXXXXXXXXXXXX |
| root | 127.0.0.1 | *C7E2F6338326EDC0AXXXXXXXXXXXXXXXXXXXXXXX |
+------+-----------+-------------------------------------------+
rows in set (0.00 sec) mysql> exit
Bye
[root@localhost ~]# mysql -u root -p #再次登录
Enter password: #输入刚才的密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.5. MySQL Community Server (GPL) Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> exit
Bye
[root@localhost ~]#