Ubuntu 下安装 mysql

运行下面的shell代码

#安装mysql
sudo apt-get -y install mysql-server
sudo apt-get -y install mysql-client
sudo apt-get -y install libmysqlclient-dev

安装过程中会提示你创建root账户

那就创建 要把root账户密码记下来 不要弄丢咯

mysql 测试

sudo mysqld --initialize
2018-10-17T06:25:56.353286Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-10-17T06:25:56.354004Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2018-10-17T06:25:56.354012Z 0 [ERROR] Aborting
systemctl start mysqld

弹出一个messagebox 让我输入密码我不确定是输入mysql的root密码还是Ubuntu的root密码,感觉应该是要输入mysql的root密码.但是我还是决定要先试一下Ubuntu的root密码.所以输入Ubuntu的root密码

结果输出

Failed to start mysqld.service: Unit mysqld.service not found.

启动失败,猜想是输入密码错误了.换mysql的root密码,这个root密码就是在安装mysql的时候初始创建的.

systemctl start mysqld

然后我用mysql的root密码测试居然还是不行.

那个上面的问题应该就是输入Ubuntu的密码.至于为什么不能成功应该从错误输出找原因. 启动mysqld服务失败的原因是:

Unit mysqld.service not found

先不管 先看看别的

如果看到有mysql 的socket处于 listen 状态则表示安装成功

sudo netstat -tap|grep mysql
tcp 0 0 localhost:mysql *:* LISTEN 1071/mysqld

通过以下命令来检查MySQL服务器是否启动:

ps -ef | grep mysqld
mysql 1071 1 0 10月17 ? 00:00:38 /usr/sbin/mysqld
yourname 12237 18990 0 12:10 pts/2 00:00:00 grep --color=auto mysqld
mysql -u root -p

可以登录

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.7.23-0ubuntu0.16.04.1 (Ubuntu) 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>
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> exit;
Bye

关闭MYSQL服务

./mysqladmin -u root -p shutdown
Enter password:

测试是否关闭成功

sudo netstat -tap|grep mysql
out put nothing
ps -ef | grep mysqld
yourname 20242 18990 0 12:15 pts/2 00:00:00 grep --color=auto mysqld

看不到mysql的服务了

然后我再把MYSQL的服务启动起来

cd /usr/bin
./mysqld_safe &
2018-10-18T04:17:34.530613Z mysqld_safe Logging to syslog.
2018-10-18T04:17:34.540702Z mysqld_safe Logging to '/var/log/mysql/error.log'.
./mysqld_safe: 152: ./mysqld_safe: cannot create /var/log/mysql/error.log: Permission denied
2018-10-18T04:17:34.548777Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.
./mysqld_safe: 152: ./mysqld_safe: cannot create /var/log/mysql/error.log: Permission denied

这几乎代表着启动失败…

看一下

ps -ef|grep mysqld
liuzy 26197 18990 0 12:18 pts/2 00:00:00 grep --color=auto mysqld

看不到,服务没有启动起来,然后sudo加权限 测试

sudo nohup ./mysqld_safe &

没有出现什么错误,然后测下

ps -ef|grep mysqld
liuzy 5254 18990 0 12:26 pts/2 00:00:00 grep --color=auto mysqld

跟刚才一样… 换个命令测试

 sudo netstat -tap|grep mysql
out put nothing

神马也没有输出来,尝试登录下mysql

mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

已经不能登录成功了…

当前msyql服务器运行环境

cat /etc/issue
Ubuntu 16.04.5 LTS \n \l

查看mysqld启动是的缺省选项

mysqld --print-defaults
mysqld would have been started with the following arguments:
--user=mysql --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306 --basedir=/usr --datadir=/var/lib/mysql --tmpdir=/tmp --lc-messages-dir=/usr/share/mysql --skip-external-locking --bind-address=127.0.0.1 --key_buffer_size=16M --max_allowed_packet=16M --thread_stack=192K --thread_cache_size=8 --myisam-recover-options=BACKUP --query_cache_limit=1M --query_cache_size=16M --log_error=/var/log/mysql/error.log --expire_logs_days=10 --max_binlog_size=100M

查看mysqld启动配置文件的优先级

mysqld --verbose --help|grep -A 1 "default options"
mysqld: Can't change dir to '/var/lib/mysql/' (Errcode: 13 - Permission denied)
--no-defaults Don't read default options from any option file,
except for login file.
--defaults-file=# Only read default options from the given file #.
--defaults-extra-file=# Read this file after the global files are read.

查看当前的my.cnf配置文件

sudo mysqld &
ps -ef|grep mysql
root 9758 18990 0 12:50 pts/2 00:00:00 sudo mysqld
liuzy 10745 18990 0 12:51 pts/2 00:00:00 grep --color=auto mysql
ps -ef | grep mysqld
root 9758 18990 0 12:50 pts/2 00:00:00 sudo mysqld
liuzy 12677 18990 0 12:52 pts/2 00:00:00 grep --color=auto mysqld
ps -ef|grep mysql|grep -v grep
root 9758 18990 0 12:50 pts/2 00:00:00 sudo mysqld
service mysql start
need to input root password

接着

mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.23-0ubuntu0.16.04.1 (Ubuntu) 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>
ps -ef|grep mysql|grep -v grep
yourname 20232 18990 0 13:18 pts/2 00:00:00 vim mysqld.cnf
mysql 28771 1 0 13:23 ? 00:00:00 /usr/sbin/mysqld

这就是说在Ubuntu中可以用service来启动mysql服务

那么我尝试下用service关闭 mysql服务

service mysql stop
need to input root password
ps -ef|grep mysql|grep -v grep
yourname 20232 18990 0 13:18 pts/2 00:00:00 vim mysqld.cnf

Ubuntu mysql安装与使用的更多相关文章

  1. Ubuntu Mysql 安装

    下载 http://dev.mysql.com/downloads/mysql/ 选择 Linux- Generic 选择版本 wget http://cdn.mysql.com/Downloads/ ...

  2. ubuntu mysql安装及需要其他主机连服务器mysql时的设置(error:10061)

    说明: 一个朋友在使用ubuntu-server 16.04安装mysql,设置远程访问的时候出现了问题,请我帮忙.但是,我也没有使用过ubuntu安装mysql,于是乎搜索了很多技术文件,比着葫芦画 ...

  3. ubuntu mysql 安装和外网访问配置

    1.输入 sudo apt-get install mysql-server 安装过程中会让你输入密码,这个密码是root的密码. 安装完毕后,就可以正常使用了,如果你需要外网用户能够连接继续下面的步 ...

  4. Ubuntu mysql安装,还有可视化界面

    安装mysql sudo apt-get install mysql-server sudo apt-get install mysql-client sudo apt-get install lib ...

  5. ubuntu MySQL安装和设置

    1. apt-get install mysql-server 2. apt-get isntall mysql-client 修改 /etc/mysql/my.cnf #bind-address   ...

  6. 转:CentOS/Debian/Ubuntu一键安装LAMP(Apache/MySQL/PHP)环境

    CentOS/Debian/Ubuntu一键安装LAMP(Apache/MySQL/PHP) 今天遇到一个网友提到需要在Linux VPS服务器中安装LAMP(Apache/MySQL/PHP)网站环 ...

  7. Ubuntu 下安装 Mysql

    这里讲用Ubuntu下安装MySql ubuntu上安装mysql非常简单只需要几条命令就可以完成. 1. sudo apt-get install mysql-server   2. apt-get ...

  8. Ubuntu MYSQL和Windows MYSQL (非C盘安装)

    1.Ubuntu 默认安装 Mysql 5.6版本以上: 1.查看系统是否安装mysql 数据库: sudo netstat -tap | grep mysql 如果安装了,就查看一下版本命令: my ...

  9. ubuntu下安装mysql

    现在的软件越来越好安装,尤其是在ubuntu下安装软件,更是没有技巧,只需要在联网的情况下使用apt-get inatll 即可.在决定安装mysql之前,要先确定系统是否已经安装mysql.如下图: ...

随机推荐

  1. 截断误差VS舍入误差

     截断误差:是指计算某个算式时没有精确的计算结果,如积分计算,无穷级数计算等,使用极限的形式表达的,显然我们只能截取有限项进行计算,此时必定会有误差存在,这就是截断误差. 舍入误差:是指由于计算机表示 ...

  2. 洛谷P1090——合并果子(贪心)

    https://www.luogu.org/problem/show?pid=1090 题目描述 在一个果园里,多多已经将所有的果子打了下来,而且按果子的不同种类分成了不同的堆.多多决定把所有的果子合 ...

  3. 还不知道PHP有闭包?那你真OUT了

    做过一段时间的Web开发,我们都知道或者了解JavaScript中有个非常强大的语法,那就是闭包.其实,在PHP中也早就有了闭包函数的功能.早在5.3版本的PHP中,闭包函数就已经出现了.到了7以及后 ...

  4. PHP获取目录中的全部内容RecursiveDirectoryIterator

    这次我们来介绍一个SPL库中的目录迭代器,它的作用其实非常简单,从名字就可以看出来,就是获取指定目录下的所有内容.之前我们要遍历目录获取目录及目录下的所有文件一般是需要进行递归遍历的,自己写这个代码说 ...

  5. Java面向对象系列(1)- 什么是面向对象

    面向过程 & 面向对象 面向过程思想 步骤清晰清楚,第一步做什么,第二步做什么-- 面对过程适合处理一些较为简单的问题 面向对象思想 物以类聚,分类的思维模式,思考问题首先会解决问题需要哪些分 ...

  6. 『GoLang』控制结构

    条件语句 if 是用于测试某个条件(布尔型或逻辑型)的语句,如果该条件成立,则会执行if后由大括号括起来的代码块,否则就忽略该代码块继续执行后续的代码. if condition { // do so ...

  7. P1251-餐巾计划问题【费用流】

    正题 题目链接:https://www.luogu.com.cn/problem/P1251 题目大意 \(N\)天,第\(i\)天需要\(a_i\)个餐巾. 每个餐巾价格为\(p\),使用完后有两种 ...

  8. Qt和JavaScript使用QWebChannel交互一——和Qt内嵌网页交互

    Qt和JavaScript使用QWebChannel交互一--和Qt内嵌网页交互 目录 Qt和JavaScript使用QWebChannel交互一--和Qt内嵌网页交互 前言 一.效果 二.实现过程 ...

  9. win32 TreeCtrl控件通知消息, LVN_SELCHANGED和LVN_ITEMCHANGED用法

    今天出了个奇怪的问题,当我在主窗口上创建一个用模板对话框的子窗口时, 在子窗口上放的TreeCtrl控件不响应LVN_SELCHANGED消息,也是晕死了, 我以为是消息捕获的问题,我在主窗口上也捕获 ...

  10. (Java)面向对象的三大特征

    封装.继承与多态 封装 封装的作用(好处) 提高程序安全性,保护数据 隐藏代码的实现细节 统一接口 增加系统可维护性 属性私有(关键字private) 加上Private可使该属性私有于一个类,在其他 ...