Home > Database > Mysql Tutorial > body text

Ubuntu 安装 Mysql 5.6 数据库

WBOY
Release: 2016-06-07 15:13:12
Original
1455 people have browsed it

Ubuntu 安装 Mysql 5.6 数据库 1)下载: mysql-5.6.13-debian6.0-x86_64.deb http://dev.mysql.com/downloads/mirror.php?id=413956 2)安装: $ sudo dpkg -i mysql-5.6.3-debian6.0-x86_64.deb Mysql Server 初始化在:/opt/mysql/server-5.6 3)配置: $

Ubuntu 安装 Mysql 5.6 数据库

1)下载:

mysql-5.6.13-debian6.0-x86_64.deb

http://dev.mysql.com/downloads/mirror.php?id=413956

2)安装:

$ sudo dpkg -i mysql-5.6.3-debian6.0-x86_64.deb
Copy after login

Mysql Server 初始化在:/opt/mysql/server-5.6

3)配置:

$ sudo groupadd mysql

$ sudo useradd -r -g mysql mysql

$ sudo apt-get install libaio-dev    # 这个不知道有什么用

$ sudo ln -s /opt/mysql/server-5.6 /usr/local/mysql

$ sudo mkdir /usr/local/mysql/data

$ sudo chown -R mysql. /usr/local/mysql/data
Copy after login
# 初始化数据库

$ sudo /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

# 将mysqld的启动shell放到系统服务目录下:

$ sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

#将mysql的配置文件放到系统配置下/etc/, mysql在全局范围内使用这个配置文件:

$ sudo cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
Copy after login

4) 启动/停止 Mysql

$ sudo /etc/init.d/mysql start

$ sudo /etc/init.d/mysql stop
Copy after login


5) 更改mysql root管理员密码为 abc. 强烈建议开发的机器密码: root

$ sudo /usr/local/mysql/bin/mysqladmin -u root password abc
Copy after login

6) 登录到mysql (启动之后)

$ sudo /usr/local/mysql/bin/mysql -u root -p 
# 或者

$ sudo /usr/local/mysql/bin/mysql -u root -p

# 显示数据库
> show databases;
# 使用数据库
> use 数据库名;
> 显示全部表
> show tables;

# 输出重定向到文件
> tee /home/sqlc.txt
# windows:
> tee "c:/temp/sqlc.txt"
# 接下来的sql语句输出都重定向到文件: sqlc.txt
> show create table mytest;
> select * from mytest;

# 退出mysql控制台
> exit;

# 远程登入 mysql. 用户名:root, 密码:123456 远程服务器ip:192.168.1.88 服务协议端口: 3306 远程数据库名: testdb
$ mysql -u root -p123456 -h 192.168.1.88 -P 3306 -D testdb
Copy after login

在windows上执行的是下面的程序:

C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql.exe

参考文档:

http://www.360doc.com/content/12/0919/18/8006573_237073873.shtml

7) mysql的时间戳用法

Mysql中的表, 如果需要同时每条记录的创建时间和任何一个字段更新的时间, 可以按下面的方式:

mysql>

CREATETABLE mytest (
        name VARCHAR(100),
        create_time DATETIME,
        update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATECURRENT_TIMESTAMP)
Copy after login

然后创建触发器:

delimiter|
CREATETRIGGER default_datetime BEFORE INSERT ON test6
        for each row
                  if new.create_time is null then
                           set new.create_time = now();
                  end if; |
delimiter;
Copy after login

这样每当插入新记录时, create_time, update_time会自动记录当前时间. 任何更新都会导致update_time自动更新.


8) mysql服务器开启允许远程连接

假设我的 Mysql 服务器安装在机器A, 当我在另外一台机器B或本机A用远程连接我的Mysql时,发现远程连接失败。原来Mysql默认安装不开启允许远程连接。因此需要开启远程连接。

# 在机器A上,用Mysql本地连接接入 Mysql:

$ /usr/local/mysql/bin/mysql -u root -p
mysql > grant all privileges on *.* to 'root'@'%' identified by 'root123' with grant option;

mysql> flush privileges;

mysql> exit;

# 在远程客户机器上安装mysql客户端, 并连接服务

$ sudo apt-get install mysql-client-core-5.5

$ mysql -u root -P 3306 -h 192.168.92.117 -proot123
Copy after login





Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!