mysql安装

Posted cjw1219

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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]
    default-character-set = utf8
    
    [mysql]
    user=root
    password='1234'
    default-character-set = utf8
    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.02 sec)
  • 删除mysql

# 查看是否有安装的mysql
[root@test ~]# rpm -qa | grep -i mysql
mysql-community-libs-5.7.26-1.el7.x86_64
mysql57-community-release-el7-11.noarch
mysql-community-server-5.7.26-1.el7.x86_64
mysql-community-common-5.7.26-1.el7.x86_64
mysql-community-client-5.7.26-1.el7.x86_64

[root@test ~]# yum list install mysql*
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.njupt.edu.cn
 * updates: mirrors.163.com
已安装的软件包
mysql-community-client.x86_64      5.7.26-1.el7 @mysql57-community
mysql-community-common.x86_64      5.7.26-1.el7 @mysql57-community
mysql-community-libs.x86_64        5.7.26-1.el7 @mysql57-community
mysql-community-server.x86_64      5.7.26-1.el7 @mysql57-community
mysql57-community-release.noarch   el7-11       installed        

# 卸载mysql安装包
[root@test ~]# yum remove mysql mysql-server mysql-libs compat-mysql51
删除:
 mysql-community-client.x86_64 0:5.7.26-1.el7                                            mysql-community-libs.x86_64 0:5.7.26-1.el7                 
 mysql-community-server.x86_64 0:5.7.26-1.el7     
[root@test ~]# yum -y remove mysql-community-common-5.7.26-1.el7.x86_64
[root@test ~]# yum remove mysql57-community-release-el7-11.noarch


# 删除Mysql残余文件
[root@test ~]# whereis mysql
mysql: /usr/share/mysql
[root@test ~]# rm -rf /usr/share/mysql/
[root@test ~]# find / -name mysql
find: ‘/run/user/1000/gvfs’: 权限不够
/etc/selinux/targeted/active/modules/100/mysql
/etc/selinux/targeted/tmp/modules/100/mysql
/var/lib/mysql
/var/lib/mysql/mysql
[root@test ~]# rm -rf /etc/selinux/targeted/active/modules/100/mysql /etc/selinux/targeted/tmp/modules/100/mysql  /var/lib/mysql /var/lib/mysql/mysql

乌班图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:Windowssystem32>tasklist |findstr mysqld
mysqld.exe                    8896 Services                   0    452,760 K

C:Windowssystem32>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:Windowssystem32>net stop mysql
C:Windowssystem32>mysqld --skip-grant-tables
mysql> update mysql.user set password=password(1) where user='root' and host='localhost';
mysql> flush privileges; # 刷新权限

# 使用新密码登录
C:Windowssystem32>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
--------------

以上是关于mysql安装的主要内容,如果未能解决你的问题,请参考以下文章

从mysql的片段中加载ListView

连接MySQL出现错误:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)(代码片段

使用 json rereiver php mysql 在片段中填充列表视图

在Tomcat的安装目录下conf目录下的server.xml文件中增加一个xml代码片段,该代码片段中每个属性的含义与用途

PHP代码-psysh调试代码片段工具

关于mysql驱动版本报错解决,Cause: com.mysql.jdbc.exceptions.jdbc4Unknown system variable ‘query_cache_size(代码片段