mysql安装集合

1 阿里云linux环境mysql rpm安装

执行命令rpm -qa | grep -i mysql,检查Linux服务器中Mysql及相关RPM包
通过rpm -e对rpm保进行删除
mysql安装集合_第1张图片
卸载出现下面的问题,可参考Linux安装卸载Mysql数据库
1
执行rpm -ivh MySQL-shared-compat-advanced-5.6.22-1.el7.x86_64.rpm,提示错误

error: Failed dependencies:
        mariadb-libs is obsoleted by MySQL-shared-compat-advanced-5.6.22-1.el7.x86_64

mariadb
分析原因,是要卸载掉MariaDB,因为CentOS的默认数据库已经不再是MySQL了,而是MariaDB
MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。
执行命令rpm -qa | grep mariadb,检查到mariadb的rpm
mariadb
执行命令rpm -e --nodeps mariadb-libs-5.5.40-1.el7_0.x86_64进行卸载
然后执行命令

 rpm -ivh MySQL-shared-compat-advanced-5.6.22-1.el7.x86_64.rpm
 rpm -ivh MySQL-client-advanced-5.6.22-1.el7.x86_64.rpm
 rpm -ivh MySQL-devel-advanced-5.6.22-1.el7.x86_64.rpm
 rpm -ivh MySQL-embedded-advanced-5.6.22-1.el7.x86_64.rpm
 rpm -ivh MySQL-server-advanced-5.6.22-1.el7.x86_64.rpm
 rpm -ivh MySQL-shared-advanced-5.6.22-1.el7.x86_64.rpm
 rpm -ivh MySQL-test-advanced-5.6.22-1.el7.x86_64.rpm

执行命令,修改mysql的密码

#修改配置文件位置
cp /usr/share/mysql/my-default.cnf /etc/my.cnf
#初始化MySQL及设置密码
/usr/bin/mysql_install_db
service mysql start
#查看root账号密码
cat /root/.mysql_secret 
# The random password set for the root user at Wed Dec 11 23:32:50 2013 (local time): qKTaFZnl

修改mysql的默认密码

/etc/init.d/mysql stop   (service mysqld stop )

/usr/bin/mysqld_safe --skip-grant-tables

另外开个SSH连接

[root@localhost ~]# mysql

mysql>use mysql

mysql>update user set password=password("test1234") where user="root";

mysql>flush privileges;

mysql>exit



#pkill -KILL -t pts/0 可将pts为0的**用户(之前运行mysqld_safe的用户窗口)强制踢出

正常启动 MySQL:/etc/init.d/mysql start   (service mysqld start)

允许远程访问

01
mysql> use mysql;
02
mysql> select host,user,password from user;
03
+-----------------------+------+-------------------------------------------+
04
| host                  | user | password                                  |
05
+-----------------------+------+-------------------------------------------+
06
| localhost             | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
07
| localhost.localdomain | root | *1237E2CE819C427B0D8174456DD83C47480D37E8 |
08
| 127.0.0.1             | root | *1237E2CE819C427B0D8174456DD83C47480D37E8 |
09
| ::1                   | root | *1237E2CE819C427B0D8174456DD83C47480D37E8 |
10
+-----------------------+------+-------------------------------------------+
11
 
12
mysql> update user set password=password('123456') where user='root';
13
mysql> update user set host='%' where user='root' and host='localhost';
14
mysql> flush privileges;
15
mysql> exit

修改mysql默认字符集,将/etc/my.cnf,替换为下面的内容。

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[client]
port = 3306
default-character-set=utf8
[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
port = 3306
character_set_server=utf8
character_set_client=utf8
collation-server=utf8_general_ci
lower_case_table_names=1
max_connections=1000
[mysql]
default-character-set = utf8 

mac电脑mysql密码忘了怎么办

关闭mysql服务器
sudo /usr/local/mysql/support-files/mysql.server stop
也可以在系统偏好里有个MySQL里关闭。
cd /usr/local/mysql/bin    进入目录
sudo su 获取权限
 ./mysqld_safe --skip-grant-tables & 重启服务器
重开个终端,
配置短命令:

alias mysql=/usr/local/mysql/bin/mysql

输入mysql 进入mysql命令模式
use mysql进入mysql数据库
flush privileges;大概就是获取权限,要不他不让你改。
set password for 'root'@'localhost'=password('新密码'); 完成修改

如果想全局更改别名

cd ~
open -e .bash_profile
# 写入下面的内容
alias mysql=/usr/local/mysql/bin/mysql
alias mysqladmin=/usr/local/mysql/bin/mysqladmin
# 执行source命令使配置生效。
source .bash_profile

2 mac电脑中安装mysql
先通过下面的命令,安装brew,我的mysql版本时8.0.12

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 

接着通过brew install mysql,my.cnf配置参考MAC 安装MySQL my.cnf配置文件,但如果你想理解里面配置的含义,可以参见mysql my.cnf的相关配置,这里面写的相当详细。
按照上面的配置,确实在localhost里面可以将mysql运行起来,但是问题是远程访问存在问题了。
解决mac上mysql不能远程访问的问题,在这篇文章找到了遇到同样问题的人,可喜可乐。实验一下,看看是否有成果。我的下面没有找到
bind-address,防火墙也是关闭的,这又一个诧异的地方。
mysql安装集合_第2张图片
查看他们说的homebrew.mxcl.mysql.plist,也没有看到bind-address,难道是mysql版本的问题,我现在的问题时8.0.12,我找到的资料版本都是5.x版本。还需继续寻找答案。
mysql安装集合_第3张图片
在上图中即使加上bind-address也无济于事。从进程分析来看/etc/my.cnf么有作用,于是将其删掉,mysql照样启动.执行brew list mysql,发现原来brew安装的mysql,配置文件时从/usr/local/Cellar/mysql/8.0.12/.bottle/etc/my.cnf中设置的,更改后重启mysql即可。

# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
#bind-address = 127.0.0.1
bind-address=0.0.0.0

java链接mysql8的时候发生错误

caching_sha2_password

故创建用户需要按照下面的方式创建

create user 'your username'@'%' identified with mysql_native_password by 'your password’
flush privileges

接着又出现另外一个问题,这个是因为程序中mysql的驱动版本太低。需要将mysql-connector-java驱动版本升级

Caused by: java.sql.SQLException: Unknown system variable 'tx_read_only'
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996) ~[mysql-connector-java-5.1.34.jar:5.1.34]
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3887) ~[mysql-connector-java-5.1.34.jar:5.1.34]```
如果在mac电脑下安装navicat,可以参考[navicat下载](http://www.pc6.com/mac/111878.html),
mac允许其他来源软件,参考[Mac打开应用提示已损坏怎么办 Mac安装软件时提示已损坏怎么办](http://www.pc6.com/edu/168719.html)
**3 ubuntu安装mysql**
参考[ubuntu 18.04用apt安装mysql-server](https://www.cnblogs.com/ddif/p/9876502.html)
```sh
# 卸载mysql
sudo apt-get --purge remove mysql-server mysql-common mysql-client
# 安装mysql
sudo apt-get install mysql-server mysql-common mysql-client
# 修改mysql配置
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
# 设置监听地址为
bind-address = 0.0.0.0
# 修改root用户的密码
mysql
select user, plugin from mysql.user;
update mysql.user set authentication_string=PASSWORD('000000'),plugin='mysql_native_password' where user='root';
flush privileges;
grant all on *.* to root@'%' identified by '000000' with grant option;
flush privileges;
exit
# 重启mysql
service mysql restart
# 查看mysql是否安装成功
sudo apt-get install net-tools
sudo netstat -tap | grep mysql

你可能感兴趣的:(mysql)