4.20+Linux+Mysql服务器搭建

来源:互联网 发布:head first python下载 编辑:程序博客网 时间:2024/06/12 01:07

MySQL服务器搭建


  1. VMware安装
  2. Xshell安装
  3. Mysql安装
  4. Java中连接MySql
  5. C语言中连接MySql

-直接从MySql设置开始
-成功安装之后

t1-cs-sicnu@cs-sicnu:~$ whereis mysqlmysql: /usr/bin/mysql /usr/lib/mysql /etc/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gzt1-cs-sicnu@cs-sicnu:~$ 

-查看Mysql进程

t1-cs-sicnu@cs-sicnu:~$ ps -aux | grep mysqlmysql       891  0.0  0.1   4476  1692 ?        Ss   09:31   0:00 /bin/sh /usr/bin/mysqld_safemysql      1256  0.7 13.3 795492 133404 ?       Sl   09:31   0:02 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --log-error=/var/log/mysql/error.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306t1-cs-s+   2026  0.0  0.2  13712  2144 pts/8    S+   09:36   0:00 grep --color=auto mysqlt1-cs-sicnu@cs-sicnu:~$ 

-查看运行端口

root@cs-sicnu:/home/t1-cs-sicnu# netstat -tpan | grep mysqltcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      1256/mysqld   

-启动Mysql

root@cs-sicnu:/home/t1-cs-sicnu# mysql -uroot -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.6.31-0ubuntu0.15.10.1 (Ubuntu)

-查看ip

root@cs-sicnu:/home/t1-cs-sicnu# ifconfigeno16777736 Link encap:以太网  硬件地址 00:0c:29:b1:55:49            inet 地址:192.168.43.128  广播:192.168.43.255  掩码:255.255.255.0          inet6 地址: fe80::20c:29ff:feb1:5549/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  跃点数:1          接收数据包:78453 错误:0 丢弃:0 过载:0 帧数:0          发送数据包:16289 错误:0 丢弃:0 过载:0 载波:0          碰撞:0 发送队列长度:1000           接收字节:105937442 (105.9 MB)  发送字节:1694129 (1.6 MB)          中断:19 基本地址:0x2000 

-只对本地监听

root@cs-sicnu:~# netstat -anp | grep 3306tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      1256/mysqld  

-修改mysql 的myconf文件;

root@cs-sicnu:~# mysql --help | grep 'Default options' -A 1Default options are read from the following files in the given order:/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf 
root@cs-sicnu:~# find / -name my.cnf/etc/alternatives/my.cnf/etc/mysql/my.cnf/var/lib/dpkg/alternatives/my.cnf^Croot@cs-sicnu:~# mysql --help | grep my.cnf                      order of preference, my.cnf, $MYSQL_TCP_PORT,/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf root@cs-sicnu:~# vim /etc/my.cnf

-打开任何my.conf都么有发现bind-address;
于是cat my.cnf

root@cs-sicnu:/usr# cat /etc/mysql/my.cnf## The MySQL database server configuration file.## You can copy this to one of:# - "/etc/mysql/my.cnf" to set global options,# - "~/.my.cnf" to set user-specific options.# # One can use all long options that the program supports.# Run program with --help to get a list of available options and with# --print-defaults to see which it would actually understand and use.## For explanations see# http://dev.mysql.com/doc/mysql/en/server-system-variables.html## * IMPORTANT: Additional settings that can override those from this file!#   The files must end with '.cnf', otherwise they'll be ignored.#!includedir /etc/mysql/conf.d/!includedir /etc/mysql/mysql.conf.d/

进入 mysql.conf.d

root@cs-sicnu:/etc/mysql/mysql.conf.d# cat mysqld.cnf 

内容如下:

skip-external-locking## 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## * Fine Tuning

成功找到bind-address。前面加上# 注释掉。监听任何连接。

# localhost which is more compatible and is not less secure.#bind-address           = 127.0.0.1

以下代码防坑

root@cs-sicnu:~# sudo restart mysqlrestart: 无法连接到 Upstart: Failed to connect to socket /com/ubuntu/upstart: 拒绝连接root@cs-sicnu:~# service restart mysqlrestart: unrecognized serviceroot@cs-sicnu:~# service restart mysqldrestart: unrecognized serviceroot@cs-sicnu:~# restart mysqldrestart: 无法连接到 Upstart: Failed to connect to socket /com/ubuntu/upstart: 拒绝连接root@cs-sicnu:~# service mysql restartroot@cs-sicnu:~# 

进入到Mysql

mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || cstest             || cstestt1           || mysql              || performance_schema |+--------------------+5 rows in set (0.06 sec)mysql> 

对数据库任何主机访问权限,赋予权限;

mysql> grant all privileges on *.* TO 'root'@'%'identified by '1314' with grant option;Query OK, 0 rows affected (0.00 sec)

修改生效;

mysql> FLUSH PRIVILEGES;Query OK, 0 rows affected (0.00 sec)

退出mysql;

mysql> exit;Byeroot@cs-sicnu:~# 

使用另一个Linux登陆;

root@t2-cs-sicnu:/home/t2-cs-sicnu# whereis mysqlmysql: /usr/bin/mysql /etc/mysql /usr/lib/mysql /usr/bin/X11/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gzroot@t2-cs-sicnu:/home/t2-cs-sicnu# mysql -uroot -p -h 192.168.43.128 -P3306Enter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 4Server version: 5.6.31-0ubuntu0.15.10.1 (Ubuntu)Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> 

查看表格;

mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || cstest             || cstestt1           || mysql              || performance_schema |+--------------------+5 rows in set (0.01 sec)mysql> 

成功!!!!!!

0 0
原创粉丝点击