Wednesday, November 8, 2023

MySQL: You do not have the SUPER privilege and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)

 For future reference, this is what I did.

When checking the database, I found "log_bin_trust_function_creators" was set to "Off".

Code:
mysql> SHOW VARIABLES LIKE 'log_bin_trust_function_creators';
+---------------------------------+-------+
| Variable_name                   | Value |
+---------------------------------+-------+
| log_bin_trust_function_creators |  OFF  |
+---------------------------------+-------+
Therefore, as suggested by Atsushi , we can simply set it to "On" (1).
Code:
mysql> SET GLOBAL log_bin_trust_function_creators = 1;
The other option is to update the user to Super.
We can see the users Super privileges like this:
Code:
mysql> SELECT Host,User,Super_priv FROM mysql.user;
+-----------+------------------+------------+
| Host      | User             | Super_priv |
+-----------+------------------+------------+
| %         | zabbix1          |     N      |
| %         | zabbix2          |     N      |
| %         | zabbixf          |     N      |
| localhost | mysql.infoschema |     N      |
| localhost | mysql.session    |     Y      |
| localhost | mysql.sys        |     N      |
| localhost | root             |     Y      |
| localhost | zabbixdb         |     N      |
+-----------+------------------+------------+
To set a user as Super, just update the table as shown by adminjerry . ("zabbix1" user as an example)
Code:
UPDATE mysql.user SET Super_Priv='Y' WHERE user='zabbix1' AND host='%';

Wednesday, September 28, 2022

run Selenium Python Script with Headless Chrome

Installing Selenium and Webdriver for Python

We will use a virtual environment for running Python scripts. Follow the below steps to create Python virtual environment and install the required python modules.

  1. Create a directory to store Python scripts. Then switch to the newly-created directory.
    mkdir tests && cd tests 
    
  2. Set up the Python virtual environment and activate it.
    python3 -m venv venv 
    source venv/bin/activate 
    

 

Once the environment is activated, You will find the updated prompt as shown below screenshot:

Create Python Environment for Selenium on Ubuntu
Create Python Environment for Selenium on Ubuntu
Now use PIP to install the selenium and webdriver-manager Python modules under the virtual environment.
pip install selenium webdriver-manager  
 Installing Selenium and Webdriver Python Module on Ubuntu & DebianInstalling Seleniu

 

 

Selenium Python Script with Headless Chrome

 

 Now, create a sample selenium script in Python that fetches the title of a website.

This script will run headless, So you can run it without an X desktop environment. You can simply SSH to your system and run the below example. Make sure Chromedriver is install in arm64 type. See my other blog

  1. Create a Python script and edit it in your favorite text editor:
    nano test.py 
    
  2. Copy-paste the following Selenium Python script to the file.

    ====

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.chrome.service import Service
    #from webdriver_manager.chrome import ChromeDriverManager
     
    chrome_driver_path="/usr/bin/chromedriver"
    options = Options()
    options.add_argument('--headless')
    options.add_argument('--no-sandbox')
    options.add_argument('--disable-dev-shm-usage')
    #driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
     
    driver= webdriver.Chrome(executable_path=chrome_driver_path, options=options)
    driver.get("https://python.org")
    print(driver.title)
    driver.close()

     ====

     

    Press CTRL + O to save content to file and press CTRL + X to close editor.

  3. Now, run this Python script in a shell.
    python test.py 
    

    You will see the output something like below:

    Running Selenium Python Script in Ubuntu & Debian
    Running the Selenium Python Script