Ubuntu14.04安装mysql5.6

最后更新于:2022-04-01 21:49:44

## 1.前提 * 此安装方法的前提是,链接互联网 ## 2.安装mysql * 更新源 ``` sudo apt-get update ``` * 安装MySQL-client-core-5.6 ``` sudo apt-get install MySQL-client-core-5.6 ``` * 安装mysql-client-5.6 ``` sudo apt-get install mysql-client-5.6 ``` * 安装mysql-server-5.6 ``` sudo apt-get install mysql-server-5.6 ``` ## 3.检查mysql状态 > 执行完成上面的命令之后,正常情况mysql服务会自启动 * 检查mysql的启动状态 ``` ## 查看进程 ps -ef | grep mysql ## 查看端口监听 netstat -tap | grep mysql ``` * 链接mysql进行状态检查 ``` mysql -h localhost -u root -p Enter password: mysql> status; -------------- mysql Ver 14.14 Distrib 5.6.33, for debian-linux-gnu (x86_64) using EditLine wrapper Connection id: 37 Current database: Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.6.33-0ubuntu0.14.04.1 (Ubuntu) Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: latin1 Db characterset: latin1 Client characterset: utf8 Conn. characterset: utf8 UNIX socket: /var/run/mysqld/mysqld.sock Uptime: 25 min 27 sec Threads: 1 Questions: 115 Slow queries: 0 Opens: 87 Flush tables: 1 Open tables: 80 Queries per second avg: 0.075 -------------- ``` ## 4.修改必要的配置 sudo vim /etc/mysql/my.cnf * 修改远程访问 ``` # 为了可以远程访问,将[mysqld]下面的这行注释掉 # Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. # bind-address = 127.0.0.1 ``` * 修改字符编码,在client,mysqld,mysql配置段,分别追加如下编码信息 ``` [client] default-character-set = utf8 [mysqld] character-set-server=utf8 lower_case_table_names = 1 [mysql] default-character-set=utf8 ``` 再次查看status,变为utf8编码 ``` Server characterset: utf8 Db characterset: utf8 Client characterset: utf8 Conn. characterset: utf8 ``` * 新建数据库和用户 ``` create database `devicedb` default character set utf8 collate utf8_general_ci; CREATE USER 'device'@'%' IDENTIFIED BY '4rfv$RFV'; GRANT ALL ON devicedb.* TO 'device'@'%' IDENTIFIED BY '4rfv$RFV'; //只有执行了这一句才可以登陆 FLUSH PRIVILEGES; ``` ## 5.卸载旧版本 ``` #停止mysql的服务 sudo service mysql stop #删除mysql的数据文件(必要的情况下) sudo rm /var/lib/mysql/ -R #删除mqsql的配置文件 sudo rm /etc/mysql/ -R #删除mysql软件 sudo apt-get autoremove mysql* --purge ```
';