标签:账号 dev red 安装mysql 14. for end -- other
mysql的安装可以用yum安装更方便
[root@yoyo ~]# cd /usr/local/
[root@yoyo ~]# mkdir mysql-community-release
[root@yoyo ~]# cd mysql-community-release
[root@yoyo ~]# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
[root@yoyo ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm
[root@yoyo ~]# yum -y install mysql-community-server
安装完成后查看版本号:mysql -V
[root@yoyo local]# mysql -V
mysql Ver 14.14 Distrib 5.6.42, for Linux (x86_64) using EditLine wrapper
安装完成后重启mysql服务,查看状态是Active: activating,说明启动成功
[root@yoyo local]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
[root@yoyo local]# systemctl status mysql.service
● mysqld.service - MySQL Community Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: activating (auto-restart) (Result: exit-code) since Mon 2019-01-14 19:41:59 CST; 31ms ago
Process: 20074 ExecStartPost=/usr/bin/mysql-systemd-start post (code=exited, status=0/SUCCESS)
Process: 20073 ExecStart=/usr/bin/mysqld_safe --basedir=/usr (code=exited, status=1/FAILURE)
Process: 20060 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 20073 (code=exited, status=1/FAILURE)
Jan 14 19:41:59 yoyo systemd[1]: Failed to start MySQL Community Server.
Jan 14 19:41:59 yoyo systemd[1]: Unit mysqld.service entered failed state.
Jan 14 19:41:59 yoyo systemd[1]: mysqld.service failed.
[root@yoyo local]#
方法一:
初次安装使用mysql,root账户默认是没设置密码的,系统会给个临时密码,在/var/log/mysqld.log可以查看
[root@yoyo local]# grep ‘temporary password‘ /var/log/mysqld.log
如下图所示,出现的就是临时密码,复制出来就可以登录mysql了
[root@yoyo local]# mysql -u root -p
看到Enter password: 输入密码,exit退出mysql
[root@yoyo local]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 26
Server version: 5.6.42 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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@yoyo local]#
方法二:
要是上一步找不到临时密码,那就用此方法,先停掉mysql,以安全方式启动
[root@yoyo local]# systemctl stop mysql.service
以安全方式启动mysql:
[root@yoyo local]# /usr/bin/mysqld_safe --skip-grant-tables >/dev/null 2>&1 &
然后执行
[root@yoyo local]# /usr/bin/mysql -u root mysql
出现“mysql>”提示符后输入:
mysql> update user set password = Password('root') where User = 'root';
回车后执行(刷新MySQL系统权限相关的表):
mysql> flush privileges;
再执行exit退出:
mysql> exit;
退出后,使用以下命令登陆mysql,试试是否成功:
[root@yoyo local]#mysql -u root -p
按提示输入密码:root
[root@yoyo local]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 27
Server version: 5.6.42 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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>
出现Welcome to the MySQL那就是登录成功了
mysql默认端口是3306,如何查看msyql端口号呢?可以用root账号登录后,执行show variables like ‘port‘;
[root@yoyo local]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 33
Server version: 5.6.42 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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> show variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0.00 sec)
mysql>
mysql在linux上安装完成后,为了方便的查看,可以在本地电脑上安装一个远程连接数据库的客户端,远程连上mysql
mysql>create user 'username'@'%' identified by 'password';
标签:账号 dev red 安装mysql 14. for end -- other
原文地址:https://www.cnblogs.com/yoyoketang/p/10268896.html