💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# 安装 ubuntu安装 1\. 在线安装 ``` sudo apt-get update sudo apt-get install mysql-server ``` 2\. 初始化 ``` sudo mysql_secure_installation ``` ``` #1 VALIDATE PASSWORD PLUGIN can be used to test passwords... Press y|Y for Yes, any other key for No: N (我的选项) #2 Please set the password for root here... New password: (输入密码) Re-enter new password: (重复输入) #3 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) : N (我的选项) #4 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 (我的选项) #5 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) : N (我的选项) #6 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 (我的选项) ``` ``` mysqladmin -u root password "new_password"; ``` 越过密码 ``` [root@server-10 ~]# vim /etc/my.cnf skip-grant-tables ##跳过权限表,这样启动数据库以后,就可以无密码登录! ``` 3\. 查看mysql状态 ``` systemctl status mysql.service ``` 4\. 配置远程访问 ``` 1. 登录mysql,命令:mysql -u root -p,然后输入密码即可。 2. use mysql 3. select user,host from user 4. update user set host="%" where user="root" 5. flush privileges ``` 5.添加用户 ``` root@host# mysql -u root -p Enter password:******* mysql> use mysql; Database changed mysql> INSERT INTO user (host, user, password, select_priv, insert_priv, update_priv) VALUES ('localhost', 'guest', PASSWORD('guest123'), 'Y', 'Y', 'Y'); Query OK, 1 row affected (0.20 sec) mysql> FLUSH PRIVILEGES; Query OK, 1 row affected (0.01 sec) mysql> SELECT host, user, password FROM user WHERE user = 'guest'; +-----------+---------+------------------+ | host | user | password | +-----------+---------+------------------+ | localhost | guest | 6f8c114b58f2ce9e | +-----------+---------+------------------+ 1 row in set (0.00 sec) ``` 6\. /etc/my.cnf配置文件 ``` [client] # 设置mysql客户端默认字符集 default-character-set=utf8 [mysqld] # 设置3306端口 port = 3306 # 设置mysql的安装目录 basedir=C:\\web\\mysql-8.0.11 # 设置 mysql数据库的数据的存放目录,MySQL 8+ 不需要以下配置,系统自己生成即可,否则有可能报错 # datadir=C:\\web\\sqldata # 允许最大连接数 max_connections=20 # 服务端使用的字符集默认为8比特编码的latin1字符集 character-set-server=utf8 # 创建新表时将使用的默认存储引擎 default-storage-engine=INNODB 优化: skip-name-resolve 跳过DNS解析 ``` 7\. 登录 ``` mysql -u root -p 会提示输入密码,验证登陆 mysql -uroot -p密码 会显示密码,直接登陆 登陆别人MySQL mysql -hPup 连接其他MySQL(h为host主机,P端口号:默认为3306,u:用户名,p:password密码) mysql -h ip地址 -u root -p 提示输入密码,验证登陆 ``` # ubuntu更改mysql默认数据目录 ``` 1. 进入mysql 输入: mysql> show variables like 'datadir'; +---------------+------------------------------+ | Variable_name | Value | +---------------+------------------------------+ | datadir | /opt/fsl-imx-xwayland/mysql/ | +---------------+------------------------------+ 1 row in set (0.00 sec) mysql> 查看默认路径 2. systemctl stop mysql 或 /etc/init.d/mysql stop 3. mkdir -p /data/mysql 4. cp -rp /var/lib/mysql/* /data/mysql/ chown -R mysql.mysql /data/mysql chmod -R 700 /data/mysql 5. 修改配置文件 cp /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/mysql.conf.d/mysqld.cnf.bak vim /etc/mysql/mysql.conf.d/mysqld.cnf 修改第38行为datadir = /data/mysql 6. 修改启动文件 vim /etc/apparmor.d/usr.sbin.mysqld 在第50行后面添加两行: /data/mysql/ r, /data/mysql/** rwk, 7. 配置AppArmor访问控制 vim /etc/apparmor.d/usr.sbin.mysqld 在第50行后面添加两行: /data/mysql/ r, /data/mysql/** rwk, 8. 重启服务 systemctl restart apparmor /etc/init.d/mysql restart 9. 重新1验证 ```