前言
本人在配置MySQL踩过的坑数不胜数,此文章偏向Ubuntu的小白
1.安装JDK以及配置环境变量
1.1OpenJDK
$ sudo apt update && sudo apt upgrade
JDK8:
$ sudo apt install openjdk-8-jdk
JDK9:
$ sudo apt install openjdk-9-jdk
JDK11:
$ sudo apt install openjdk-11-jdk
1.2手动安装
安装之前当然是老规矩地下载jdk:Oracle JDK官方下载
# 把jdk的文件移动到 /usr/local/ 目录下
$ sudo mv ~/jdk*.tar.gz /usr/local/
# 解压文件
$ cd /usr/local/
$ sudo tar -zxvf jdk-8u101-linux-x64.tar.gz
如需更换jdk,删除旧版本的软链接,重新创建软链接指向新版即可
$ sudo rm -rf jdk
$ sudo ln -s jdk* jdk
1.3配置环境变量
放到 /usr/local 里面的程序,建议使用系统变量。
- 用户变量
- ~/.profile 文件是用户的私有配置文件
- ~/.bashrc 是在bash里面使用的私有配置文件,优先级在 .profile 文件之后
- 系统变量
- /etc/profile 文件是系统的公用配置文件
- /etc/bash.bashrc 是bash专用的配置文件,优先级在 profile 文件之后
$ sudo vim /etc/profile.d/jdk.sh
环境变量的配置内容如下:
1.编辑/etc/profile
$ sudo gedit /etc/profile
#填入以下内容
export JAVA_HOME=/usr/local/software/jdk1.8.0_241
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
配置以后,可以重新登录让配置生效,也可以使用source临时加载配置文件。使用source命令加载的配置,仅在当前shell有效,关闭以后失效。
$ source /etc/profile.d/jdk.sh
1.4查看JDK是否安装成功,以下一条命令成功则安装成功
$ java -version
2.安装Idea
下载
安装步骤
$ sudo tar -zxvf ideaIU-2020.2.3.tar.gz -C /opt/idea
$ cd idea-IU-202.7660.26/bin/
$ ./idea.sh
勾选 Create a script … 然后一直 next
2.1如果Idea闪退
需要注意修改的是 /root/.config/JetBrains/Idea2021.3/idea64.vmoptions这一路径下的idea64.vmoptions而不是IDEA bin目录下的idea64.vmoptions,修改bin目录下的idea64.vmoptions
如果没能找到root路径下的idea64.vmoptions,可以使用如下命令寻找
$ find / -name 'idea64.vmoptions'
之后打开这一文件
$ sudo vim /root/.config/JetBrains/Idea2021.3/idea64.vmoptions
在文件中添加如下一行
-Dide.browser.jcef.enabled=false
Ubuntu Idea输入不了中文 并且打字时候光标不跟随
本人已经把Idea的错误已经解决,当然经历的各种资料的查询,保证是简单粗暴小白易上手
我的主页有解决方法
3安装MySQL
sudo apt-get install mysql-server
3.1初始化配置
sudo mysql_secure_installation
配置项较多,如下所示:
VALIDATE PASSWORD PLUGIN can be used to test passwords...
Press y|Y for Yes, any other key for No: Y(我的选项)
Please set the password for root here...
New password: (输入密码)
Re-enter new password: (重复输入)
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them...
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y (我的选项)
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network...
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y (我的选项)
By default, MySQL comes with a database named 'test' that
anyone can access...
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y (我的选项)
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (我的选
3.2检查mysql服务状态
systemctl status mysql.service
显示如下结果说明mysql服务是正常的:
![](https://i-blog.csdnimg.cn/blog_migrate/a37540dc86d0d474dfed971b5bee43c0.png)
3.3配置远程访问
在Ubuntu下MySQL缺省是只允许本地访问的,使用第三方连接工具是连不上的。
如果你要其他机器也能够访问的话,需要进行配置。
首先用根用户进入
$ sudo mysql -uroot -p
在数据库上进行设置
GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "123456";
其中root@localhos,localhost就是本地访问,配置成%就是所有主机都可连接;
第二个'123456'为你给新增权限用户设置的密码,%代表所有主机,也可以是具体的ip;
不过这随设置了%如果root通过工具还是登陆不进去,可能是为了安全性,所以需要新建数据库和用户才可以进行登入
用root用户新建数据和用作远程访问的用户
4.使用DataGrip连接数据库
4.1.下载相关资源包
链接地址:https://www.jetbrains.com/zh-cn/datagrip/
4.2.解压到自己的路径
我的是/opt/DataGrip
$ cd /home/home/Downloads
$ sudo mv datagrip /opt/DataGrip
4.3.创建快捷方式
进入/usr/share/applications,创建datagrip.desktop文件
$ cd /usr/share/applications
$ sudo gedit datagrip.desktop
将以下代码粘贴到datagrip.desktop中
[Desktop Entry]
Version=1.0
Type=Application
Name=IntelliJ DataGrip
Icon=/usr/local/src/Program_files/DataGrip-2020.2.3/bin/datagrip.svg
Exec="/usr/local/src/Program_files/DataGrip-2020.2.3/bin/datagrip.sh" %f
Comment=DataGrip
Categories=Development;DataGrip;
Terminal=false
StartupWMClass=jetbrains-datagrip
最后保存退出,关闭终端,打开菜单就可以看见datagrip图标了
$ sudo chmod 777 datagrip.desktop
DataGrip无法连接MySql数据库
Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually.
问题很简单,连接的时候添加参数 URL:
serverTimezone=GMT%2B8
5.MySQL 命令行补全工具 MyCLI
安装:
$ sudo apt install mycli
登录(登录后比起MySQL命令行多了提示)
$ mycli -u root -p