mysql安装

Centos7 MYSQL 安装配置

配置centos 7 ip地址

  • 找到vmware网卡的网关


  • 编写配置文件

    加入
    
    BOOTPROTO="static"   
    
    IPADDR=192.168.214.130
    PREFIX=24
    GATEWAY=192.168.214.2
    DNS1=114.114.114.114
    
    [java@test ~]$ cat /etc/sysconfig/network-scripts/ifcfg-ens33 
    TYPE="Ethernet"
    PROXY_METHOD="none"
    BROWSER_ONLY="no"
    BOOTPROTO="static"
    DEFROUTE="yes"
    IPADDR=192.168.214.130
    PREFIX=24
    GATEWAY=192.168.214.2
    DNS1=114.114.114.114
    IPV4_FAILURE_FATAL="no"
    IPV6INIT="yes"
    IPV6_AUTOCONF="yes"
    IPV6_DEFROUTE="yes"
    IPV6_FAILURE_FATAL="no"
    IPV6_ADDR_GEN_MODE="stable-privacy"
    NAME="ens33"
    UUID="84a84fb0-0990-416c-84ed-75b0281e88ee"
    DEVICE="ens33"
    ONBOOT="yes"
    [java@test ~]$ systemctl restart network
    

  • 安装mysql
[root@test ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
[root@test ~]# rpm -ivh mysql57-community-release-el7-11.noarch.rpm
[root@test ~]# yum install mysql-community-server
[root@test ~]# service mysqld start

  • 配置mysql
# 拿到初始化密码
[root@test ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

[root@test ~]# grep password /var/log/mysqld.log
2019-06-11T10:13:27.590735Z 1 [Note] A temporary password is generated for root@localhost: w>hkh#Ua0)P_
[root@test ~]# mysql -uroot -p'w>hkh#Ua0)P_'

mysql> set global validate_password_policy=0; 
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)

# 即使改为密码规则设置为1,centos系统最低的设置密码的规则是4,所以最短只能设置4位数密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '1234';
Query OK, 0 rows affected (0.00 sec)


# 授权其他用户登录这台数据库
mysql> GRANT ALL PRIVILEGES ON *.* TO 'java'@'%' IDENTIFIED BY '1234' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)

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


# 设置默认的字符编码
[root@test ~]# vim /etc/my.cnf
[client]
port=3306
socket=/var/lib/mysql/mysql.sock
default-character-set=utf8

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
# symbolic-links=0
character-set-server=utf8


[mysql]
user=root
password=123456
no-auto-rehash
default-character-set=utf8



[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

# 进入mysql查看字符编码类型
mysql> SHOW VARIABLES LIKE '%char%';
+--------------------------------------+----------------------------+
| Variable_name                        | Value                      |
+--------------------------------------+----------------------------+
| character_set_client                 | utf8                       |
| character_set_connection             | utf8                       |
| character_set_database               | utf8                       |
| character_set_filesystem             | binary                     |
| character_set_results                | utf8                       |
| character_set_server                 | utf8                       |
| character_set_system                 | utf8                       |
| character_sets_dir                   | /usr/share/mysql/charsets/ |
| validate_password_special_char_count | 1                          |
+--------------------------------------+----------------------------+
9 rows in set (0.00 sec)


乌班图MYSQL配置

ip地址配置

root@java-virtual-machine:~# cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto lo

iface lo inet loopback

auto ens33
iface ens33 inet static
address 192.168.142.12
gateway 192.168.142.2

# 永久设置DNS(也可以在/etc/resolv.conf 下临时添加 nameserver 223.5.5.5)
java@java-virtual-machine:~$ sed -n '/DNS/p' /etc/systemd/resolved.conf |grep -v '^#'
DNS=223.5.5.5

(参考链接 https://unix.stackexchange.com/questions/128220/how-do-i-set-my-dns-when-resolv-conf-is-being-overwritten)

# 重启网卡,如果重启网卡不生效,则重启机器
root@java-virtual-machine:~# /etc/init.d/networking restart 

    
# 安装ssh 服务
root@java-virtual-machine:~# apt-get update
root@java-virtual-machine:~# apt install openssh-server
root@java-virtual-machine:~# systemctl start ssh


配置python环境


# 重装python3-pip
root@java-virtual-machine:~# apt install python3-pip
    
# 配置pycharm (https://blog.csdn.net/jpch89/article/details/81739176)

1. 将pycharm安装包解压后放入/usr/local/bin/ 目录下
2. 将pycharm 加入桌面后添加可执行权限,然后打开
# vim pycharm.desktop
[Desktop Entry]
Name = PyCharm
Type = Application
Exec = /usr/local/bin/pycharm-2019.1.3/bin/pycharm.sh
Icon = /usr/local/bin/pycharm-2019.1.3/bin/pycharm.png
Terminal = False

3. 将桌面生成的程序放入应用程序目录 /usr/share/applications/
# cp pycharm.desktop /usr/share/applications/

4. 激活pycharm
http://idea.lanyus.com/

MYSQL安装


apt-get install mysql-server
apt-get install mysql-client
apt-get install libmysqlclient-dev

# 检查是否安装成功
apt install net-tools  # 安装netstat
netstat -tap | grep mysql

MYSQL配置

# 设置root密码
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| db1                |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

mysql> use mysql;
mysql> update user set authentication_string=PASSWORD("123") where user="root";
mysql> update user set plugin="mysql_native_password";
mysql> flush privileges;
mysql> quit
root@test:~# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
    
# 统一字符编码
[mysql]
#default-character-set=utf8  # 如果加上这句话,可能会导致无法输入中文
user=root
password=123

[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci 

# 允许外部访问

# 默认只允许本机访问
root@java-virtual-machine:/home/java# lsof -i:3306
COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mysqld  6293 mysql   33u  IPv4  68596      0t0  TCP localhost:mysql (LISTEN)
    
# 修改配置文件
root@java-virtual-machine:~# vim /etc/mysql/mysql.conf.d/mysqld.cnf
bind-address            = 0.0.0.0  #默认是127.0.0.1
root@java-virtual-machine:~# systemctl restart mysql.service
    
# 进入mysql进行授权
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123' WITH GRANT OPTION;
flush PRIVILEGES;

windows MYSQL 配置

下载MYSQL 
https://dev.mysql.com/downloads/file/?id=484971
    
# 安装mysql后找不到服务或出现找不到指定文件
输入 regedit -注册表编辑器-HKEY_LOCAL_MACHINE--->SYSTEM--->CurrentControlSet--->Services--->MySQL-ImagePath(修改为正确的mysql安装路径)-重启mysql

# 把mysqld软件做成系统服务

>>> 关掉mysqld
C:\Windows\system32>tasklist |findstr mysqld
mysqld.exe                    8896 Services                   0    452,760 K

C:\Windows\system32>taskkill /f /pid 8896
成功: 已终止 PID 为 8896 的进程
    
>>> 设置
services.msc

>>> 查看结果
services.msc

>>> 删除服务
sc delete mysql(服务名)


# mysql在服务在命令行的停止和启动
net start mysql 
net stop mysql

# 修改初始值的密码
mysqladmin -uroot -p password 123

# 再次登录
mysql -uroot -p123


# 破解Mysql管理员密码
C:\Windows\system32>net stop mysql
C:\Windows\system32>mysqld --skip-grant-tables
mysql> update mysql.user set password=password(1) where user='root' and host='localhost';
mysql> flush privileges; # 刷新权限

# 使用新密码登录
C:\Windows\system32>mysql -uroot -p1  # 使用新密码登录

#统一字符编码
mysql> \s  # 默认编码是GBK
--------------
mysql  Ver 14.14 Distrib 5.6.44, for Win64 (x86_64)

Connection id:          3
Current database:
Current user:           root@localhost
SSL:                    Not in use
Using delimiter:        ;
Server version:         5.6.44 MySQL Community Server (GPL)
Protocol version:       10
Connection:             localhost via TCP/IP
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    gbk
Conn.  characterset:    gbk
TCP port:               3306
Uptime:                 12 hours 27 min 36 sec

Threads: 1  Questions: 5  Slow queries: 0  Opens: 67  Flush tables: 1  Open tables: 60  Queries per second avg: 0.000
--------------

>>> 在mysql的项目目录下 自定义配置文件 my.ini 
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8
user='root'
password=1

>>> 重启服务,查看编码
mysql> \s
--------------
mysql  Ver 14.14 Distrib 5.6.44, for Win64 (x86_64)

Connection id:          5
Current database:
Current user:           root@localhost
SSL:                    Not in use
Using delimiter:        ;
Server version:         5.6.44 MySQL Community Server (GPL)
Protocol version:       10
Connection:             localhost via TCP/IP
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    utf8
Conn.  characterset:    utf8
TCP port:               3306
Uptime:                 12 hours 38 min 56 sec

Threads: 1  Questions: 22  Slow queries: 0  Opens: 67  Flush tables: 1  Open tables: 60  Queries per second avg: 0.000
--------------
posted @ 2019-10-11 22:50  cjw1219  阅读(271)  评论(0编辑  收藏  举报