mysql installation on ubuntu14.04

本文主要简单介绍下在ubutnu上面mysql的检测,安装,启动的相关步骤和注意事项.

一: 检测PC上是否安装了mysql如下是没有安装的情况
useful reference:
https://stackoverflow.com/questions/27614574/how-can-i-check-if-mysql-is-installed-on-ubuntu
如下是没有安装的情况:

$ dpkg -s mysql-server | grep Status
dpkg-query: package 'mysql-server' is not installed and no information is available
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents.
$ mysql
The program 'mysql' can be found in the following packages:
 * mysql-client-core-5.7
 * mariadb-client-core-10.0
Try: sudo apt install <selected package>

二: 安装mysql
useful reference:
https://www.linode.com/docs/databases/mysql/install-mysql-on-ubuntu-14-04/
http://www.runoob.com/mysql/mysql-install.html
https://www.ilanni.com/?p=13197
step 1:

sudo apt-get update
sudo apt-get upgrade

step2:

sudo apt-get install mysql-server mysql-client

其中mysql-server是mysql服务器, 可以在本机上实现数据库相关服务.
mysql-client 是客户端程序, 用于连接并操作mysql server. 如果你不需要在本地建立数据库, 只需要远程连接操作在另一台机器上的mysql server那就只需要安装mysql client.
过程中会提示你设置一个mysql 的root密码.

step3: 登录

$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 47
Server version: 5.5.55-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2017, 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> 

(之前安装的时候设置了root用户的password. 此时如果你的PC当前用户是root可以直接用命令mysql登录, 如果你的PC当前用户不是root, 就要用mysql -u root -p, 再输入密码登录.)
恭喜你安装成功啦.

三: mysql安装后
1: 安装状态

$ dpkg -s mysql-server | grep Status
Status: install ok installed

$ dpkg -s mysql-client | grep Status
Status: install ok installed

$ dpkg --get-selections | grep mysql
libdbd-mysql-perl               install
libmysqlclient18:amd64              install
libmysqlclient18:i386               install
libqt4-sql-mysql:i386               install
mysql-client                    install
mysql-client-5.5                install
mysql-client-core-5.5               install
mysql-common                    install
mysql-server                    install
mysql-server-5.5                install
mysql-server-core-5.5               install

$ dpkg --get-selections | grep mysql
libmysqlclient18:i386               install
libqt4-sql-mysql:i386               install
mysql-client-core-5.5               install
mysql-common                        install

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

2: 安版本的检测
(1) 在终端运行

$ mysql -V或者 mysql --version
mysql  Ver 14.14 Distrib 5.5.55, for debian-linux-gnu (x86_64) using readline 6.3

$ mysql --help |grep Distrib
mysql  Ver 14.14 Distrib 5.5.55, for debian-linux-gnu (x86_64) using readline 6.3

(2) 登录mysql查看

mysql> select version();
+-------------------------+
| version()               |
+-------------------------+
| 5.5.55-0ubuntu0.14.04.1 |
+-------------------------+
1 row in set (0.00 sec)


mysql> status
--------------
mysql  Ver 14.14 Distrib 5.5.55, for debian-linux-gnu (x86_64) using readline 6.3

Connection id:      47
Current database:   
Current user:       root@localhost
SSL:            Not in use
Current pager:      stdout
Using outfile:      ''
Using delimiter:    ;
Server version:     5.5.55-0ubuntu0.14.04.1 (Ubuntu)
Protocol version:   10
Connection:     Localhost via UNIX socket
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    latin1
Conn.  characterset:    latin1
UNIX socket:        /var/run/mysqld/mysqld.sock
Uptime:         2 days 17 hours 33 min 28 sec

Threads: 1  Questions: 586  Slow queries: 0  Opens: 189  Flush tables: 1  Open tables: 41  Queries per second avg: 0.002

3: configuration配置相关
下面有几个mysql比较重要的目录以及文件.
(1) 数据库的存放目录
/var/lib/mysql (默认) 该路径下面你可以看到你创建的数据库, 可以通过配置文件更改保存路径. 下次介绍更改步骤.
(2) 配置文件
/usr/share/mysql
/etc/mysql/my.cnf (非常重要)
(3) 相关重要命令
/usr/bin

root@ubuntu:/usr/bin# ls *sql*
msql2mysql         mysql_convert_table_format  mysql_install_db           mysql_setpermission  mysql_waitpid  mysqladmin    mysqlbug      mysqld_safe    mysqlhotcopy   mysqlrepair  mysqlslap
mysql              mysql_find_rows             mysql_plugin               mysql_tzinfo_to_sql  mysql_zap      mysqlanalyze  mysqlcheck    mysqldump      mysqlimport    mysqlreport  mysqltest
mysql_client_test  mysql_fix_extensions        mysql_secure_installation  mysql_upgrade mysqlaccess    mysqlbinlog   mysqld_multi  mysqldumpslow  mysqloptimize  mysqlshow

(4) 启动脚本
/etc/init.d/mysql

Tips: 之前在检测版本的时候我遇到了一个问题, 如下是问题以及解决方法,希望对大家有帮助.

$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

https://stackoverflow.com/questions/11657829/error-2002-hy000-cant-connect-to-local-mysql-server-through-socket-var-run

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值